From 06105ac289f18cf710d0dc611c3eca1cfb96736e Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Fri, 9 Feb 2024 09:59:03 +0100 Subject: [PATCH] Fix incorrect name format --- src/Dto/Screenshot.php | 2 +- src/Normalizer/ScreenshotNormalizer.php | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Dto/Screenshot.php b/src/Dto/Screenshot.php index 0e30627..b58fac2 100644 --- a/src/Dto/Screenshot.php +++ b/src/Dto/Screenshot.php @@ -24,7 +24,7 @@ final class Screenshot public null|string $platform = null; - public null|string $format = null; + public null|string $type = null; public function getLabel(): null|string|TranslatableInterface { diff --git a/src/Normalizer/ScreenshotNormalizer.php b/src/Normalizer/ScreenshotNormalizer.php index 494b35e..8e83f5c 100644 --- a/src/Normalizer/ScreenshotNormalizer.php +++ b/src/Normalizer/ScreenshotNormalizer.php @@ -30,16 +30,11 @@ public function __construct( public function normalize(mixed $object, string $format = null, array $context = []): array { assert($object instanceof Screenshot); - $url = null; $asset = null; - $imageFormat = null; - if (! str_starts_with($object->src->src, '/')) { + $imageType = $object->type; + if ($imageType === null && ! str_starts_with($object->src->src, '/')) { $asset = $this->assetMapper->getAsset($object->src->src); - $url = $asset?->publicPath; - $imageFormat = $this->getFormat($object, $asset); - } - if ($url === null) { - $url = $object->src->src; + $imageType = $this->getType($asset); } ['sizes' => $sizes, 'formFactor' => $formFactor] = $this->getSizes($object, $asset); @@ -49,7 +44,7 @@ public function normalize(mixed $object, string $format = null, array $context = 'form_factor' => $formFactor, 'label' => $object->label, 'platform' => $object->platform, - 'format' => $imageFormat, + 'format' => $imageType, ]; $cleanup = static fn (array $data): array => array_filter( @@ -103,12 +98,8 @@ private function getSizes(Screenshot $object, null|MappedAsset $asset): array ]; } - private function getFormat(Screenshot $object, ?MappedAsset $asset): ?string + private function getType(?MappedAsset $asset): ?string { - if ($object->format !== null) { - return $object->format; - } - if ($this->imageProcessor === null || $asset === null || ! class_exists(MimeTypes::class)) { return null; }