diff --git a/src/DataCollector/PwaCollector.php b/src/DataCollector/PwaCollector.php index 0fb7862..ddf3916 100644 --- a/src/DataCollector/PwaCollector.php +++ b/src/DataCollector/PwaCollector.php @@ -48,7 +48,7 @@ public function __construct( ) { } - public function collect(Request $request, Response $response, Throwable $exception = null): void + public function collect(Request $request, Response $response, ?Throwable $exception = null): void { $jsonOptions = [ AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, diff --git a/src/Normalizer/AssetNormalizer.php b/src/Normalizer/AssetNormalizer.php index 0b108d3..dc40999 100644 --- a/src/Normalizer/AssetNormalizer.php +++ b/src/Normalizer/AssetNormalizer.php @@ -21,29 +21,29 @@ public function __construct( /** * @return array{src: string, sizes?: string, form_factor?: string, label?: string, platform?: string, format?: string} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): string + public function normalize(mixed $data, ?string $format = null, array $context = []): string { - assert($object instanceof Asset); + assert($data instanceof Asset); $url = null; - if (! str_starts_with($object->src, '/')) { - $asset = $this->assetMapper->getAsset($object->src); + if (! str_starts_with($data->src, '/')) { + $asset = $this->assetMapper->getAsset($data->src); $url = $asset?->publicPath; } if ($url === null) { - $url = $object->src; + $url = $data->src; } return $url; } - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { assert(is_string($data)); return Asset::create($data); } - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Asset; } @@ -51,7 +51,7 @@ public function supportsNormalization(mixed $data, string $format = null, array public function supportsDenormalization( mixed $data, string $type, - string $format = null, + ?string $format = null, array $context = [] ): bool { return $type === Asset::class; diff --git a/src/Normalizer/IconNormalizer.php b/src/Normalizer/IconNormalizer.php index 3b26704..1043f31 100644 --- a/src/Normalizer/IconNormalizer.php +++ b/src/Normalizer/IconNormalizer.php @@ -23,17 +23,17 @@ public function __construct( /** * @return array{src: string, sizes?: string, type?: string, purpose?: string} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - assert($object instanceof Icon); - $icon = $this->iconResolver->getIcon($object); - $imageType = $this->iconResolver->getType($object->type, $icon->url); + assert($data instanceof Icon); + $icon = $this->iconResolver->getIcon($data); + $imageType = $this->iconResolver->getType($data->type, $icon->url); $result = [ 'src' => $icon->url, - 'sizes' => $object->getSizeList(), + 'sizes' => $data->getSizeList(), 'type' => $imageType, - 'purpose' => $object->purpose, + 'purpose' => $data->purpose, ]; $cleanup = static fn (array $data): array => array_filter( @@ -44,7 +44,7 @@ public function normalize(mixed $object, ?string $format = null, array $context return $cleanup($result); } - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Icon; } diff --git a/src/Normalizer/ScreenshotNormalizer.php b/src/Normalizer/ScreenshotNormalizer.php index 1e58d3b..cedce7f 100644 --- a/src/Normalizer/ScreenshotNormalizer.php +++ b/src/Normalizer/ScreenshotNormalizer.php @@ -28,23 +28,23 @@ public function __construct( /** * @return array{src: string, sizes?: string, form_factor?: string, label?: string, platform?: string, format?: string} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - assert($object instanceof Screenshot); + assert($data instanceof Screenshot); $asset = null; - $imageType = $object->type; - if ($imageType === null && ! str_starts_with($object->src->src, '/')) { - $asset = $this->assetMapper->getAsset($object->src->src); + $imageType = $data->type; + if ($imageType === null && ! str_starts_with($data->src->src, '/')) { + $asset = $this->assetMapper->getAsset($data->src->src); $imageType = $this->getType($asset); } - ['sizes' => $sizes, 'formFactor' => $formFactor] = $this->getSizes($object, $asset); + ['sizes' => $sizes, 'formFactor' => $formFactor] = $this->getSizes($data, $asset); $result = [ - 'src' => $this->normalizer->normalize($object->src, $format, $context), + 'src' => $this->normalizer->normalize($data->src, $format, $context), 'sizes' => $sizes, 'form_factor' => $formFactor, - 'label' => $object->label, - 'platform' => $object->platform, + 'label' => $data->label, + 'platform' => $data->platform, 'format' => $imageType, ]; @@ -55,7 +55,7 @@ public function normalize(mixed $object, ?string $format = null, array $context return $cleanup($result); } - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Screenshot; } @@ -105,8 +105,7 @@ private function getType(?MappedAsset $asset): ?string return null; } - $mime = MimeTypes::getDefault(); - return $mime->guessMimeType($asset->sourcePath); + return MimeTypes::getDefault()->guessMimeType($asset->sourcePath); } private function getFormFactor(?int $width, ?int $height): ?string diff --git a/src/Normalizer/ServiceWorkerNormalizer.php b/src/Normalizer/ServiceWorkerNormalizer.php index 98cce36..2480074 100644 --- a/src/Normalizer/ServiceWorkerNormalizer.php +++ b/src/Normalizer/ServiceWorkerNormalizer.php @@ -13,14 +13,14 @@ /** * @return array{scope?: string, src: string, use_cache?: bool} */ - public function normalize(mixed $object, ?string $format = null, array $context = []): array + public function normalize(mixed $data, ?string $format = null, array $context = []): array { - assert($object instanceof ServiceWorker); + assert($data instanceof ServiceWorker); $result = [ - 'src' => '/' . trim($object->dest, '/'), - 'scope' => $object->scope, - 'use_cache' => $object->useCache, + 'src' => '/' . trim($data->dest, '/'), + 'scope' => $data->scope, + 'use_cache' => $data->useCache, ]; $cleanup = static fn (array $data): array => array_filter( @@ -30,7 +30,7 @@ public function normalize(mixed $object, ?string $format = null, array $context return $cleanup($result); } - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof ServiceWorker; } diff --git a/src/Normalizer/UrlNormalizer.php b/src/Normalizer/UrlNormalizer.php index df4c12e..84ebafb 100644 --- a/src/Normalizer/UrlNormalizer.php +++ b/src/Normalizer/UrlNormalizer.php @@ -24,31 +24,31 @@ public function __construct( ) { } - public function normalize(mixed $object, ?string $format = null, array $context = []): string + public function normalize(mixed $data, ?string $format = null, array $context = []): string { - assert($object instanceof Url); + assert($data instanceof Url); // If the path is a valid URL, we return it directly - if (str_starts_with($object->path, '/') && filter_var($object->path, FILTER_VALIDATE_URL) !== false) { - return $object->path; + if (str_starts_with($data->path, '/') && filter_var($data->path, FILTER_VALIDATE_URL) !== false) { + return $data->path; } // If the path is an asset, we return the public path - $asset = $this->assetMapper->getAsset($object->path); + $asset = $this->assetMapper->getAsset($data->path); if ($asset !== null) { return $asset->publicPath; } // Otherwise, we try to generate the URL try { - return $this->router->generate($object->path, $object->params, $object->pathTypeReference); + return $this->router->generate($data->path, $data->params, $data->pathTypeReference); } catch (Throwable) { // If the URL cannot be generated, we return the path as is - return $object->path; + return $data->path; } } - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Url; }