8000 minor #54308 Add more explicit nullable types for default null values… · symfony/symfony@b9b35dc · GitHub
[go: up one dir, main page]

Skip to content

Commit b9b35dc

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 ------- e9d30ba Add more explicit nullable types for default null values
2 parents 8c9979b + e9d30ba commit b9b35dc

File tree

35 files changed

+80
-60
lines changed
  • Normalizer
  • Validator/Tests/Fixtures
  • VarDumper/Tests/Fixtures
  • 35 files changed

    +80
    -60
    lines changed

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/ContainerAwareFixture.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@ class ContainerAwareFixture implements FixtureInterface, ContainerAwareInterface
    2020
    {
    2121
    public $container;
    2222

    23-
    public function setContainer(ContainerInterface $container = null)
    23+
    public function setContainer(?ContainerInterface $container = null)
    2424
    {
    2525
    $this->container = $container;
    2626
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapper.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -15,7 +15,7 @@ class StringWrapper
    1515
    {
    1616
    private $string;
    1717

    18-
    public function __construct(string $string = null)
    18+
    public function __construct(?string $string = null)
    1919
    {
    2020
    $this->string = $string;
    2121
    }

    src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -525,7 +525,7 @@ public function testBaselineFileWriteError()
    525525
    $this->expectException(\ErrorException::class);
    526526
    $this->expectExceptionMessageMatches('/[Ff]ailed to open stream: Permission denied/');
    527527

    528-
    set_error_handler(static function (int $errno, string $errstr, string $errfile = null, int $errline = null): bool {
    528+
    set_error_handler(static function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null): bool {
    529529
    if ($errno & (E_WARNING | E_WARNING)) {
    530530
    throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
    531531
    }

    src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -32,7 +32,7 @@ public function connect(array $params, $username = null, $password = null, array
    3232
    return $this->driver->connect($params, $username, $password, $driverOptions);
    3333
    }
    3434

    35-
    public function getDatabasePlatform(ServerVersionProvider $versionProvider = null): AbstractPlatform
    35+
    public function getDatabasePlatform(?ServerVersionProvider $versionProvider = null): AbstractPlatform
    3636
    {
    3737
    return $this->driver->getDatabasePlatform($versionProvider);
    3838
    }

    src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -28,6 +28,7 @@
    2828
    use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
    2929
    use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
    3030
    use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\MultipleArgumentsOptionalScalarNotReallyOptional;
    31+
    use Symfony\Component\DependencyInjection\Tests\Fixtures\OptionalParameter;
    3132
    use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
    3233
    use Symfony\Component\DependencyInjection\TypedReference;
    3334
    use Symfony\Contracts\Service\Attribute\Required;
    @@ -405,6 +406,9 @@ public function testResolveParameter()
    405406
    $this->assertEquals(Foo::class, $container->getDefinition('bar')->getArgument(0));
    406407
    }
    407408

    409+
    /**
    410+
    * @group legacy
    411+
    */
    408412
    public function testOptionalParameter()
    409413
    {
    410414
    $container = new ContainerBuilder();

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/Bar.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -15,12 +15,12 @@ class Bar implements BarInterface
    1515
    {
    1616
    public $quz;
    1717

    18-
    public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = [], iterable $baz = [])
    18+
    public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?BarInterface $decorated = null, array $foo = [], iterable $baz = [])
    1919
    {
    2020
    $this->quz = $quz;
    2121
    }
    2222

    23-
    public static function create(\NonExistent $nonExistent = null, $factory = null)
    23+
    public static function create(?\NonExistent $nonExistent = null, $factory = null)
    2424
    {
    2525
    }
    2626
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@ public function setFoosVariadic(Foo $foo, Foo ...$foos)
    2020
    $this->foo = $foo;
    2121
    }
    2222

    23-
    public function setFoosOptional(Foo $foo, Foo $fooOptional = null)
    23+
    public function setFoosOptional(Foo $foo, ?Foo $fooOptional = null)
    2424
    {
    2525
    $this->foo = $foo;
    2626
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/BarOptionalArgument.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,7 @@ class BarOptionalArgument
    66
    {
    77
    public $foo;
    88

    9-
    public function __construct(\stdClass $foo = null)
    9+
    public function __construct(?\stdClass $foo = null)
    1010
    {
    1111
    $this->foo = $foo;
    1212
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/Foo.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -9,7 +9,7 @@ public static function createBar()
    99
    return new Bar(new \stdClass());
    1010
    }
    1111

    12-
    public static function createBarArguments(\stdClass $stdClass, \stdClass $stdClassOptional = null)
    12+
    public static function createBarArguments(\stdClass $stdClass, ?\stdClass $stdClassOptional = null)
    1313
    {
    1414
    return new Bar($stdClass);
    1515
    }
    Lines changed: 23 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,23 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
    13+
    14+
    use Symfony\Component\DependencyInjection\Tests\Compiler\A;
    15+
    use Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface;
    16+
    use Symfony\Component\DependencyInjection\Tests\Compiler\Foo;
    17+
    18+
    class OptionalParameter
    19+
    {
    20+
    public function __construct(?CollisionInterface $c = null, A $a, ?Foo $f = null)
    21+
    {
    22+
    }
    23+
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@
    88
    #[When(env: 'dev')]
    99
    class Foo implements FooInterface, Sub\BarInterface
    1010
    {
    11-
    public function __construct($bar = null, iterable $foo = null, object $baz = null)
    11+
    public function __construct($bar = null, ?iterable $foo = null, ?object $baz = null)
    1212
    {
    1313
    }
    1414

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php

    Lines changed: 5 additions & 12 deletions
    Original file line numberDiff line numberDiff line change
    @@ -99,7 +99,7 @@ public function __construct(A $a, DInterface $d)
    9999

    100100
    class E
    101101
    {
    102-
    public function __construct(D $d = null)
    102+
    public function __construct(?D $d = null)
    103103
    {
    104104
    }
    105105
    }
    @@ -155,13 +155,6 @@ public function __construct(Dunglas $j, Dunglas $k)
    155155
    }
    156156
    }
    157157

    158-
    class OptionalParameter
    159-
    {
    160-
    public function __construct(CollisionInterface $c = null, A $a, Foo $f = null)
    161-
    {
    162-
    }
    163-
    }
    164-
    165158
    class BadTypeHintedArgument
    166159
    {
    167160
    public function __construct(Dunglas $k, NotARealClass $r)
    @@ -195,7 +188,7 @@ public function __construct(A $k, $foo, Dunglas $dunglas, array $bar)
    195188

    196189
    class MultipleArgumentsOptionalScalar
    197190
    {
    198-
    public function __construct(A $a, $foo = 'default_val', Lille $lille = null)
    191+
    public function __construct(A $a, $foo = 'default_val', ?Lille $lille = null)
    199192
    {
    200193
    }
    201194
    }
    @@ -211,7 +204,7 @@ public function __construct(A $a, Lille $lille, $foo = 'some_val')
    211204
    */
    212205
    class ClassForResource
    213206
    {
    214-
    public function __construct($foo, Bar $bar = null)
    207+
    public function __construct($foo, ?Bar $bar = null)
    215208
    {
    216209
    }
    217210

    @@ -350,7 +343,7 @@ public function setBar()
    350343
    {
    351344
    }
    352345

    353-
    public function setOptionalNotAutowireable(NotARealClass $n = null)
    346+
    public function setOptionalNotAutowireable(?NotARealClass $n = null)
    354347
    {
    355348
    }
    356349

    @@ -399,7 +392,7 @@ class DecoratorImpl implements DecoratorInterface
    399392

    400393
    class Decorated implements DecoratorInterface
    401394
    {
    402-
    public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = [])
    395+
    public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?DecoratorInterface $decorated = null, array $foo = [])
    403396
    {
    404397
    }
    405398
    }

    src/Symfony/Component/Filesystem/Tests/Fixtures/MockStream/MockStream.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -28,7 +28,7 @@ class MockStream
    2828
    * @param string|null $opened_path If the path is opened successfully, and STREAM_USE_PATH is set in options,
    2929
    * opened_path should be set to the full path of the file/resource that was actually opened
    3030
    */
    31-
    public function stream_open(string $path, string $mode, int $options, string &$opened_path = null): bool
    31+
    public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null): bool
    3232
    {
    3333
    return true;
    3434
    }

    src/Symfony/Component/Form/Tests/Fixtures/ChoiceList/DeprecatedChoiceListFactory.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,15 +9,15 @@
    99

    1010
    class DeprecatedChoiceListFactory implements ChoiceListFactoryInterface
    1111
    {
    12-
    public function createListFromChoices(iterable $choices, callable $value = null): ChoiceListInterface
    12+
    public function createListFromChoices(iterable $choices, ?callable $value = null): ChoiceListInterface
    1313
    {
    1414
    }
    1515

    16-
    public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value = null): ChoiceListInterface
    16+
    public function createListFromLoader(ChoiceLoaderInterface $loader, ?callable $value = null): ChoiceListInterface
    1717
    {
    1818
    }
    1919

    20-
    public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, callable $index = null, callable $groupBy = null, $attr = null): ChoiceListView
    20+
    public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, ?callable $index = null, ?callable $groupBy = null, $attr = null): ChoiceListView
    2121
    {
    2222
    }
    2323
    }

    src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -19,7 +19,7 @@ class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable,
    1919
    {
    2020
    private $array;
    2121

    22-
    public function __construct(array $array = null)
    22+
    public function __construct(?array $array = null)
    2323
    {
    2424
    $this->array = $array ?: [];
    2525
    }

    src/Symfony/Component/Form/Tests/Fixtures/FixedTranslator.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -22,7 +22,7 @@ public function __construct(array $translations)
    2222
    $this->translations = $translations;
    2323
    }
    2424

    25-
    public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
    25+
    public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
    2626
    {
    2727
    return $this->translations[$id] ?? $id;
    2828
    }

    src/Symfony/Component/HttpKernel/Tests/Fixtures/DataCollector/CloneVarDataCollector.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -24,7 +24,7 @@ public function __construct($varToClone)
    2424
    $this->varToClone = $varToClone;
    2525
    }
    2626

    27-
    public function collect(Request $request, Response $response, \Throwable $exception = null)
    27+
    public function collect(Request $request, Response $response, ?\Throwable $exception = null)
    2828
    {
    2929
    $this->data = $this->cloneVar($this->varToClone);
    3030
    }

    src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -19,7 +19,7 @@ class NonTraversableArrayObject implements \ArrayAccess, \Countable, \Serializab
    1919
    {
    2020
    private $array;
    2121

    22-
    public function __construct(array $array = null)
    22+
    public function __construct(?array $array = null)
    2323
    {
    2424
    $this->array = $array ?: [];
    2525
    }

    src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -19,7 +19,7 @@ class TraversableArrayObject implements \ArrayAccess, \IteratorAggregate, \Count
    1919
    {
    2020
    private $array;
    2121

    22-
    public function __construct(array $array = null)
    22+
    public function __construct(?array $array = null)
    2323
    {
    2424
    $this->array = $array ?: [];
    2525
    }

    src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -194,7 +194,7 @@ public function getA()
    194194
    *
    195195
    * @param ParentDummy|null $parent
    196196
    */
    197-
    public function setB(ParentDummy $parent = null)
    197+
    public function setB(?ParentDummy $parent = null)
    198198
    {
    199199
    }
    200200

    src/Symfony/Component/Routing/Tests/Fixtures/RedirectableUrlMatcher.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -19,7 +19,7 @@
    1919
    */
    2020
    class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
    2121
    {
    22-
    public function redirect(string $path, string $route, string $scheme = null): array
    22+
    public function redirect(string $path, string $route, ?string $scheme = null): array
    2323
    {
    2424
    return [
    2525
    '_controller' => 'Some controller reference...',

    src/Symfony/Component/Serializer/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
    }

    src/Symfony/Component/Serializer/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
    }

    src/Symfony/Component/Serializer/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'];

    src/Symfony/Component/Serializer/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
    }

    src/Symfony/Component/Serializer/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
    }

    src/Symfony/Component/Serializer/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
    }

    0 commit comments

    Comments
     (0)
    0