Skip to content

Commit

Permalink
Apply @smnandre's suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Simon André <[email protected]>
  • Loading branch information
Kocal and smnandre committed Nov 22, 2024
1 parent 3ea78a9 commit 6d4ead0
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Map/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Add method `Symfony\UX\Map\Renderer\AbstractRenderer::tapOptions()`, to allow Renderer to modify options before rendering a Map.
- Add `ux_map.google_maps.default_map_id` configuration to set the Google ``Map ID``
- Add compatibility with [Live Components](https://symfony.com/bundles/ux-live-component/current/index.html), for the moment only zoom, center, markers and polygons are supported.
- Add `ComponentWithMapTrait` to ease maps integration in [Live Components](https://symfony.com/bundles/ux-live-component/current/index.html)

## 2.20

Expand Down
8 changes: 4 additions & 4 deletions src/Map/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Usage with Live Components
To use a Map inside a Live Component, you need to use the ``ComponentWithMapTrait`` trait
and implement the method ``instantiateMap`` to return a ``Map`` instance.

You can interact with the Map by using `LiveAction`
You can interact with the Map by using ``LiveAction`` attribute:

.. code-block::
Expand Down Expand Up @@ -355,12 +355,12 @@ You can interact with the Map by using `LiveAction`
}
}
Then, you can render the map with ``ux_map()`` in your template:
Then, you can render the map with ``ux_map()`` in your component template:

.. code-block:: html+twig

<div{{ attributes.defaults() }}>
{{ ux_map(map, { style: 'height: 300px' }) }}
<div{{ attributes }}>
{{ ux_map(map, {style: 'height: 300px'}) }}
</div>

Then, you can define `Live Actions`_ to interact with the map from the client-side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(string $message)

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

public static function unsupportedProvider(string $provider, array $supportedProviders): self
Expand Down
6 changes: 3 additions & 3 deletions src/Map/src/Exception/UnableToNormalizeOptionsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public function __construct(string $message)
}

/**
* @param class-string<MapOptionsInterface> $classOptions
* @param class-string<MapOptionsInterface> $optionsClass
*/
public static function unsupportedProviderClass(string $classOptions): self
public static function unsupportedProviderClass(string $optionsClass): self
{
return new self(\sprintf('the class "%s" is not supported.', $classOptions));
return new self(\sprintf('the class "%s" is not supported.', $optionsClass));
}
}
8 changes: 3 additions & 5 deletions src/Map/src/Live/ComponentWithMapTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

/**
* @author Hugo Alliaume <[email protected]>
*
* @experimental
*/
trait ComponentWithMapTrait
{
Expand All @@ -34,11 +36,7 @@ abstract protected function instantiateMap(): Map;

public function getMap(): Map
{
if (null === $this->map) {
$this->map = $this->instantiateMap();
}

return $this->map;
return $this->map ??= $this->instantiateMap();
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Map/src/MapOptionsNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ public static function denormalize(array $array): MapOptionsInterface
throw UnableToDenormalizeOptionsException::missingProviderKey(self::KEY_PROVIDER);
}

if (!isset(self::$providers[$provider])) {
throw UnableToDenormalizeOptionsException::unsupportedProvider($provider, array_keys(self::$providers));
}

unset($array[self::KEY_PROVIDER]);

$class = self::$providers[$provider];
if (null === $class = self::$providers[$provider] ?? null) {
throw UnableToDenormalizeOptionsException::unsupportedProvider($provider, array_keys(self::$providers));
}

return $class::fromArray($array);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Map/src/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final public function renderMap(Map $map, array $attributes = []): string

private function getMapAttributes(Map $map): array
{
$computeId = fn (array $array) => hash('xxh3', json_encode($array));
$computeId = fn (array $array) => hash('xxh3', json_encode($array, JSON_THROW_ON_ERROR));

$attrs = $map->toArray();

Expand Down
2 changes: 1 addition & 1 deletion src/Map/tests/MapOptionsNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function tearDown(): void
public function testDenormalizingWhenProviderKeyIsMissing(): void
{
$this->expectException(UnableToDenormalizeOptionsException::class);
$this->expectExceptionMessage(' the provider key ("@provider") is missing in the normalized options.');
$this->expectExceptionMessage(' the provider key "@provider" is missing in the normalized options.');

MapOptionsNormalizer::denormalize([]);
}
Expand Down

0 comments on commit 6d4ead0

Please sign in to comment.