Skip to content

Commit 978c155

Browse files
minor #54308 Add more explicit nullable types for default null values (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- Add more explicit nullable types for default null values | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Continuing to bring deprecation-free support for PHP 8.4 (https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated) If this gets merged, I'll take care of adding missing ones in upper branches if not done during upmerge 🙂 Commits ------- e9d30bac03 Add more explicit nullable types for default null values
2 parents 1a23213 + aca54b9 commit 978c155

10 files changed

+23
-23
lines changed

Tests/Fixtures/AbstractNormalizerDummy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ public function getAllowedAttributes($classOrObject, array $context, bool $attri
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function normalize($object, string $format = null, array $context = [])
34+
public function normalize($object, ?string $format = null, array $context = [])
3535
{
3636
}
3737

3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function supportsNormalization($data, string $format = null): bool
41+
public function supportsNormalization($data, ?string $format = null): bool
4242
{
4343
return true;
4444
}
4545

4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function denormalize($data, string $type, string $format = null, array $context = [])
49+
public function denormalize($data, string $type, ?string $format = null, array $context = [])
5050
{
5151
}
5252

5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function supportsDenormalization($data, string $type, string $format = null): bool
56+
public function supportsDenormalization($data, string $type, ?string $format = null): bool
5757
{
5858
return true;
5959
}

Tests/Fixtures/DenormalizableDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class DenormalizableDummy implements DenormalizableInterface
1818
{
19-
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
19+
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = [])
2020
{
2121
}
2222
}

Tests/Fixtures/Dummy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Dummy implements NormalizableInterface, DenormalizableInterface
2323
public $baz;
2424
public $qux;
2525

26-
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
26+
public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = [])
2727
{
2828
return [
2929
'foo' => $this->foo,
@@ -33,7 +33,7 @@ public function normalize(NormalizerInterface $normalizer, string $format = null
3333
];
3434
}
3535

36-
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
36+
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = [])
3737
{
3838
$this->foo = $data['foo'];
3939
$this->bar = $data['bar'];

Tests/Fixtures/DummyString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DummyString implements DenormalizableInterface
2222
/** @var string $value */
2323
public $value;
2424

25-
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
25+
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = [])
2626
{
2727
$this->value = $data;
2828
}

Tests/Fixtures/EnvelopeNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EnvelopeNormalizer implements NormalizerInterface
2020
{
2121
private $serializer;
2222

23-
public function normalize($envelope, string $format = null, array $context = []): array
23+
public function normalize($envelope, ?string $format = null, array $context = []): array
2424
{
2525
$xmlContent = $this->serializer->serialize($envelope->message, 'xml');
2626

@@ -31,7 +31,7 @@ public function normalize($envelope, string $format = null, array $context = [])
3131
];
3232
}
3333

34-
public function supportsNormalization($data, string $format = null, array $context = []): bool
34+
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
3535
{
3636
return $data instanceof EnvelopeObject;
3737
}

Tests/Fixtures/EnvelopedMessageNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
*/
1919
class EnvelopedMessageNormalizer implements NormalizerInterface
2020
{
21-
public function normalize($message, string $format = null, array $context = []): array
21+
public function normalize($message, ?string $format = null, array $context = []): array
2222
{
2323
return [
2424
'text' => $message->text,
2525
];
2626
}
2727

28-
public function supportsNormalization($data, string $format = null, array $context = []): bool
28+
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
2929
{
3030
return $data instanceof EnvelopedMessage;
3131
}

Tests/Fixtures/NormalizableTraversableDummy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
class NormalizableTraversableDummy extends TraversableDummy implements NormalizableInterface, DenormalizableInterface
2020
{
21-
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
21+
public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = [])
2222
{
2323
return [
2424
'foo' => 'normalizedFoo',
2525
'bar' => 'normalizedBar',
2626
];
2727
}
2828

29-
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
29+
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = [])
3030
{
3131
return [
3232
'foo' => 'denormalizedFoo',

Tests/Fixtures/NotNormalizableDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct()
2424
{
2525
}
2626

27-
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
27+
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = [])
2828
{
2929
throw new NotNormalizableValueException();
3030
}

Tests/Fixtures/ScalarDummy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class ScalarDummy implements NormalizableInterface, DenormalizableInterface
2121
public $foo;
2222
public $xmlFoo;
2323

24-
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
24+
public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = [])
2525
{
2626
return 'xml' === $format ? $this->xmlFoo : $this->foo;
2727
}
2828

29-
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
29+
public function denormalize(DenormalizerInterface $denormalizer, $data, ?string $format = null, array $context = [])
3030
{
3131
if ('xml' === $format) {
3232
$this->xmlFoo = $data;

Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ public function testProvidingContextCacheKeyGeneratesSameChildContextCacheKey()
559559
$normalizer = new class() extends AbstractObjectNormalizerDummy {
560560
public $childContextCacheKey;
561561

562-
protected function extractAttributes(object $object, string $format = null, array $context = []): array
562+
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
563563
{
564564
return array_keys((array) $object);
565565
}
566566

567-
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
567+
protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = [])
568568
{
569569
return $object->{$attribute};
570570
}
@@ -599,12 +599,12 @@ public function testChildContextKeepsOriginalContextCacheKey()
599599
$normalizer = new class() extends AbstractObjectNormalizerDummy {
600600
public $childContextCacheKey;
601601

602-
protected function extractAttributes(object $object, string $format = null, array $context = []): array
602+
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
603603
{
604604
return array_keys((array) $object);
605605
}
606606

607-
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
607+
protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = [])
608608
{
609609
return $object->{$attribute};
610610
}
@@ -634,12 +634,12 @@ public function testChildContextCacheKeyStaysFalseWhenOriginalCacheKeyIsFalse()
634634
$normalizer = new class() extends AbstractObjectNormalizerDummy {
635635
public $childContextCacheKey;
636636

637-
protected function extractAttributes(object $object, string $format = null, array $context = []): array
637+
protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
638638
{
639639
return array_keys((array) $object);
640640
}
641641

642-
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
642+
protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = [])
643643
{
644644
return $object->{$attribute};
645645
}

0 commit comments

Comments
 (0)