swiss-knife
swiss-knife copied to clipboard
[finalize-classes] Finalized a class that was extended
In a folder, I have two files :
BlobNormalizer.php(non final)FileBlobNormalizer.php(final, extends BlobNormalizer)
Running vendor/bin/swiss-knife finalize-classes [folder] adds final to BlobNormalizer.
Here are the files :
<?php
declare(strict_types=1);
namespace Gammadia\Storage\Symfony\Normalizer;
use Gammadia\Storage\Blob\Blob;
use Gammadia\Storage\Blob\Utils\BlobAdapter;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Webmozart\Assert\Assert;
class BlobNormalizer implements DenormalizerInterface
{
public function __construct(
private BlobAdapter $blobAdapter,
) {
}
/**
* @param class-string $type
* @param array<mixed> $context
*/
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): Blob
{
Assert::isInstanceOf($data, UploadedFile::class);
return $this->blobAdapter->fromUploadedFile($data);
}
/**
* @param class-string $type
* @param array<mixed> $context
*/
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
{
return Blob::class === $type;
}
/**
* @return array<class-string|'*'|'object'|string, bool|null>
*/
public function getSupportedTypes(?string $format): array
{
return [Blob::class => false];
}
}
and
<?php
declare(strict_types=1);
namespace Gammadia\Storage\Symfony\Normalizer;
use Gammadia\Storage\Blob\Blob;
use Gammadia\Storage\Blob\Decorator\FileBlob;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
final class FileBlobNormalizer extends BlobNormalizer
{
/**
* @param class-string $type
* @param array<mixed> $context
*/
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): Blob
{
$blob = parent::denormalize($data, $type, $format, $context);
if (!$blob instanceof FileBlob) {
throw new NotNormalizableValueException('The blob does not have a filename.');
}
return $blob;
}
/**
* @param class-string $type
* @param array<mixed> $context
*/
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
{
return FileBlob::class === $type;
}
}
I tried adding unit tests in #22, but they do not highlight this issue.. :(
This would be hard to resolve with a unit test. Could you share the smallest possible reproducible repository? Ideally with failing Github Action, so we have the exact CLI command.
I'll check it to see if there is some glitch :slightly_smiling_face: