Skip to content

Commit b9b35dc

Browse files
minor symfony#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

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+
}

0 commit comments

Comments
 (0)