Skip to content

Commit

Permalink
minor #54308 Add more explicit nullable types for default null values…
Browse files Browse the repository at this point in the history
… (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
  • Loading branch information
nicolas-grekas committed Mar 19, 2024
2 parents 1a23213 + aca54b9 commit 978c155
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions Tests/Fixtures/AbstractNormalizerDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ 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;
}

/**
* {@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;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/DenormalizableDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
}
}
4 changes: 2 additions & 2 deletions Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/DummyString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/EnvelopeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/EnvelopedMessageNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/NormalizableTraversableDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

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',
'bar' => 'normalizedBar',
];
}

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',
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/NotNormalizableDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/ScalarDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down Expand Up @@ -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};
}
Expand Down Expand Up @@ -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};
}
Expand Down

0 comments on commit 978c155

Please sign in to comment.