From aca54b9b0e48a6068bb7c96c8002ef13ac1591c8 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sat, 16 Mar 2024 08:20:26 +0100 Subject: [PATCH] Add more explicit nullable types for default null values --- Tests/Fixtures/AbstractNormalizerDummy.php | 8 ++++---- Tests/Fixtures/DenormalizableDummy.php | 2 +- Tests/Fixtures/Dummy.php | 4 ++-- Tests/Fixtures/DummyString.php | 2 +- Tests/Fixtures/EnvelopeNormalizer.php | 4 ++-- Tests/Fixtures/EnvelopedMessageNormalizer.php | 4 ++-- Tests/Fixtures/NormalizableTraversableDummy.php | 4 ++-- Tests/Fixtures/NotNormalizableDummy.php | 2 +- Tests/Fixtures/ScalarDummy.php | 4 ++-- Tests/Normalizer/AbstractObjectNormalizerTest.php | 12 ++++++------ 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Tests/Fixtures/AbstractNormalizerDummy.php b/Tests/Fixtures/AbstractNormalizerDummy.php index ae3b411b3..a3d28c6ca 100644 --- a/Tests/Fixtures/AbstractNormalizerDummy.php +++ b/Tests/Fixtures/AbstractNormalizerDummy.php @@ -31,14 +31,14 @@ public function getAllowedAttributes($classOrObject, array $context, bool $attri /** * {@inheritdoc} */ - public function normalize($object, string $format = null, array $context = []) + public function normalize($object, ?string $format = null, array $context = []) { } /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization($data, ?string $format = null): bool { return true; } @@ -46,14 +46,14 @@ public function supportsNormalization($data, string $format = null): bool /** * {@inheritdoc} */ - public function denormalize($data, string $type, string $format = null, array $context = []) + public function denormalize($data, string $type, ?string $format = null, array $context = []) { } /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = null): bool + public function supportsDenormalization($data, string $type, ?string $format = null): bool { return true; } diff --git a/Tests/Fixtures/DenormalizableDummy.php b/Tests/Fixtures/DenormalizableDummy.php index e7c03e3d8..3170e3618 100644 --- a/Tests/Fixtures/DenormalizableDummy.php +++ b/Tests/Fixtures/DenormalizableDummy.php @@ -16,7 +16,7 @@ class DenormalizableDummy implements DenormalizableInterface { - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []) { } } diff --git a/Tests/Fixtures/Dummy.php b/Tests/Fixtures/Dummy.php index da0400593..db09a40b5 100644 --- a/Tests/Fixtures/Dummy.php +++ b/Tests/Fixtures/Dummy.php @@ -23,7 +23,7 @@ class Dummy implements NormalizableInterface, DenormalizableInterface public $baz; public $qux; - public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = []) { return [ 'foo' => $this->foo, @@ -33,7 +33,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null ]; } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []) { $this->foo = $data['foo']; $this->bar = $data['bar']; diff --git a/Tests/Fixtures/DummyString.php b/Tests/Fixtures/DummyString.php index 056de3003..4a4bef8a1 100644 --- a/Tests/Fixtures/DummyString.php +++ b/Tests/Fixtures/DummyString.php @@ -22,7 +22,7 @@ class DummyString implements DenormalizableInterface /** @var string $value */ public $value; - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []) { $this->value = $data; } diff --git a/Tests/Fixtures/EnvelopeNormalizer.php b/Tests/Fixtures/EnvelopeNormalizer.php index 1492d5d02..f321d55af 100644 --- a/Tests/Fixtures/EnvelopeNormalizer.php +++ b/Tests/Fixtures/EnvelopeNormalizer.php @@ -20,7 +20,7 @@ class EnvelopeNormalizer implements NormalizerInterface { private $serializer; - public function normalize($envelope, string $format = null, array $context = []): array + public function normalize($envelope, ?string $format = null, array $context = []): array { $xmlContent = $this->serializer->serialize($envelope->message, 'xml'); @@ -31,7 +31,7 @@ public function normalize($envelope, string $format = null, array $context = []) ]; } - public function supportsNormalization($data, string $format = null, array $context = []): bool + public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return $data instanceof EnvelopeObject; } diff --git a/Tests/Fixtures/EnvelopedMessageNormalizer.php b/Tests/Fixtures/EnvelopedMessageNormalizer.php index dfdec91b1..68a5b9470 100644 --- a/Tests/Fixtures/EnvelopedMessageNormalizer.php +++ b/Tests/Fixtures/EnvelopedMessageNormalizer.php @@ -18,14 +18,14 @@ */ class EnvelopedMessageNormalizer implements NormalizerInterface { - public function normalize($message, string $format = null, array $context = []): array + public function normalize($message, ?string $format = null, array $context = []): array { return [ 'text' => $message->text, ]; } - public function supportsNormalization($data, string $format = null, array $context = []): bool + public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return $data instanceof EnvelopedMessage; } diff --git a/Tests/Fixtures/NormalizableTraversableDummy.php b/Tests/Fixtures/NormalizableTraversableDummy.php index 55b4402b0..26bbae37e 100644 --- a/Tests/Fixtures/NormalizableTraversableDummy.php +++ b/Tests/Fixtures/NormalizableTraversableDummy.php @@ -18,7 +18,7 @@ class NormalizableTraversableDummy extends TraversableDummy implements NormalizableInterface, DenormalizableInterface { - public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = []) { return [ 'foo' => 'normalizedFoo', @@ -26,7 +26,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null ]; } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []) { return [ 'foo' => 'denormalizedFoo', diff --git a/Tests/Fixtures/NotNormalizableDummy.php b/Tests/Fixtures/NotNormalizableDummy.php index 8bb655db9..86ee6dbe5 100644 --- a/Tests/Fixtures/NotNormalizableDummy.php +++ b/Tests/Fixtures/NotNormalizableDummy.php @@ -24,7 +24,7 @@ public function __construct() { } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []) { throw new NotNormalizableValueException(); } diff --git a/Tests/Fixtures/ScalarDummy.php b/Tests/Fixtures/ScalarDummy.php index ffe4ee658..0704db31d 100644 --- a/Tests/Fixtures/ScalarDummy.php +++ b/Tests/Fixtures/ScalarDummy.php @@ -21,12 +21,12 @@ class ScalarDummy implements NormalizableInterface, DenormalizableInterface public $foo; public $xmlFoo; - public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = []) { return 'xml' === $format ? $this->xmlFoo : $this->foo; } - public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []) + public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = []) { if ('xml' === $format) { $this->xmlFoo = $data; diff --git a/Tests/Normalizer/AbstractObjectNormalizerTest.php b/Tests/Normalizer/AbstractObjectNormalizerTest.php index 5adc3d4ee..5243eb2f2 100644 --- a/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -559,12 +559,12 @@ public function testProvidingContextCacheKeyGeneratesSameChildContextCacheKey() $normalizer = new class() extends AbstractObjectNormalizerDummy { public $childContextCacheKey; - protected function extractAttributes(object $object, string $format = null, array $context = []): array + protected function extractAttributes(object $object, ?string $format = null, array $context = []): array { return array_keys((array) $object); } - protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []) + protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []) { return $object->{$attribute}; } @@ -599,12 +599,12 @@ public function testChildContextKeepsOriginalContextCacheKey() $normalizer = new class() extends AbstractObjectNormalizerDummy { public $childContextCacheKey; - protected function extractAttributes(object $object, string $format = null, array $context = []): array + protected function extractAttributes(object $object, ?string $format = null, array $context = []): array { return array_keys((array) $object); } - protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []) + protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []) { return $object->{$attribute}; } @@ -634,12 +634,12 @@ public function testChildContextCacheKeyStaysFalseWhenOriginalCacheKeyIsFalse() $normalizer = new class() extends AbstractObjectNormalizerDummy { public $childContextCacheKey; - protected function extractAttributes(object $object, string $format = null, array $context = []): array + protected function extractAttributes(object $object, ?string $format = null, array $context = []): array { return array_keys((array) $object); } - protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []) + protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []) { return $object->{$attribute}; }