Skip to content

Commit 074fa84

Browse files
Kocalsmnandre
andcommitted
Apply @smnandre's suggestions from code review
Co-authored-by: Simon André <smn.andre@gmail.com>
1 parent 3ea78a9 commit 074fa84

6 files changed

+12
-18
lines changed

src/Map/doc/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,12 @@ You can interact with the Map by using `LiveAction`
355355
}
356356
}
357357
358-
Then, you can render the map with ``ux_map()`` in your template:
358+
Then, you can render the map with ``ux_map()`` in your component template:
359359

360360
.. code-block:: html+twig
361361

362-
<div{{ attributes.defaults() }}>
363-
{{ ux_map(map, { style: 'height: 300px' }) }}
362+
<div{{ attributes }}>
363+
{{ ux_map(map, {style: 'height: 300px'}) }}
364364
</div>
365365

366366
Then, you can define `Live Actions`_ to interact with the map from the client-side.

src/Map/src/Exception/UnableToDenormalizeOptionsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(string $message)
2222

2323
public static function missingProviderKey(string $key): self
2424
{
25-
return new self(\sprintf('the provider key ("%s") is missing in the normalized options.', $key));
25+
return new self(\sprintf('the provider key "%s" is missing in the normalized options.', $key));
2626
}
2727

2828
public static function unsupportedProvider(string $provider, array $supportedProviders): self

src/Map/src/Exception/UnableToNormalizeOptionsException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function __construct(string $message)
2323
}
2424

2525
/**
26-
* @param class-string<MapOptionsInterface> $classOptions
26+
* @param class-string<MapOptionsInterface> $optionsClass
2727
*/
28-
public static function unsupportedProviderClass(string $classOptions): self
28+
public static function unsupportedProviderClass(string $optionsClass): self
2929
{
30-
return new self(\sprintf('the class "%s" is not supported.', $classOptions));
30+
return new self(\sprintf('the class "%s" is not supported.', $optionsClass));
3131
}
3232
}

src/Map/src/Live/ComponentWithMapTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ abstract protected function instantiateMap(): Map;
3434

3535
public function getMap(): Map
3636
{
37-
if (null === $this->map) {
38-
$this->map = $this->instantiateMap();
39-
}
40-
41-
return $this->map;
37+
return $this->map ??= $this->instantiateMap();
4238
}
4339

4440
/**

src/Map/src/MapOptionsNormalizer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ public static function denormalize(array $array): MapOptionsInterface
4242
throw UnableToDenormalizeOptionsException::missingProviderKey(self::KEY_PROVIDER);
4343
}
4444

45-
if (!isset(self::$providers[$provider])) {
46-
throw UnableToDenormalizeOptionsException::unsupportedProvider($provider, array_keys(self::$providers));
47-
}
48-
4945
unset($array[self::KEY_PROVIDER]);
5046

51-
$class = self::$providers[$provider];
47+
if (null === $class = self::$providers[$provider] ?? null) {
48+
throw UnableToDenormalizeOptionsException::unsupportedProvider($provider, array_keys(self::$providers));
49+
}
5250

5351
return $class::fromArray($array);
5452
}

src/Map/src/Renderer/AbstractRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ final public function renderMap(Map $map, array $attributes = []): string
8484

8585
private function getMapAttributes(Map $map): array
8686
{
87-
$computeId = fn (array $array) => hash('xxh3', json_encode($array));
87+
$computeId = fn (array $array) => hash('xxh3', json_encode($array, JSON_THROW_ON_ERROR));
8888

8989
$attrs = $map->toArray();
9090

0 commit comments

Comments
 (0)