Skip to content

Commit

Permalink
Fix incorrect name format
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Feb 9, 2024
1 parent c2355df commit 06105ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Dto/Screenshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
19 changes: 5 additions & 14 deletions src/Normalizer/ScreenshotNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 06105ac

Please sign in to comment.