From 0fc68d9630c5a2bef9e804a13ffc358ee7e928d9 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Thu, 21 Nov 2024 00:20:59 +0100 Subject: [PATCH] Apply @smnandre's suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon André --- src/Map/doc/index.rst | 6 +++--- .../src/Exception/UnableToDenormalizeOptionsException.php | 2 +- src/Map/src/Live/ComponentWithMapTrait.php | 6 +----- src/Map/src/MapOptionsNormalizer.php | 8 +++----- src/Map/src/Renderer/AbstractRenderer.php | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Map/doc/index.rst b/src/Map/doc/index.rst index ae5b3958afa..976f6259453 100644 --- a/src/Map/doc/index.rst +++ b/src/Map/doc/index.rst @@ -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 - - {{ ux_map(map, { style: 'height: 300px' }) }} + + {{ ux_map(map, {style: 'height: 300px'}) }} Then, you can define `Live Actions`_ to interact with the map from the client-side. diff --git a/src/Map/src/Exception/UnableToDenormalizeOptionsException.php b/src/Map/src/Exception/UnableToDenormalizeOptionsException.php index 095dd12972c..73f5a782e9d 100644 --- a/src/Map/src/Exception/UnableToDenormalizeOptionsException.php +++ b/src/Map/src/Exception/UnableToDenormalizeOptionsException.php @@ -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 diff --git a/src/Map/src/Live/ComponentWithMapTrait.php b/src/Map/src/Live/ComponentWithMapTrait.php index 869d6edf1eb..113b14f0e90 100644 --- a/src/Map/src/Live/ComponentWithMapTrait.php +++ b/src/Map/src/Live/ComponentWithMapTrait.php @@ -34,11 +34,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(); } /** diff --git a/src/Map/src/MapOptionsNormalizer.php b/src/Map/src/MapOptionsNormalizer.php index 214a25f5fa0..8233c00d71d 100644 --- a/src/Map/src/MapOptionsNormalizer.php +++ b/src/Map/src/MapOptionsNormalizer.php @@ -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); } diff --git a/src/Map/src/Renderer/AbstractRenderer.php b/src/Map/src/Renderer/AbstractRenderer.php index 252e3eb333e..b79d2e2c24b 100644 --- a/src/Map/src/Renderer/AbstractRenderer.php +++ b/src/Map/src/Renderer/AbstractRenderer.php @@ -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();