Skip to content

Commit c8d73fd

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Make more nullable types explicit Add more explicit nullable types for default null values
2 parents bfe8779 + 0ba1fa4 commit c8d73fd

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

Tests/Compiler/AutowirePassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface;
3636
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
3737
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
38+
use Symfony\Component\DependencyInjection\Tests\Fixtures\OptionalParameter;
3839
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
3940
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTargetAnonymous;
4041
use Symfony\Component\DependencyInjection\TypedReference;
@@ -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();

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

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
}

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
}

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
}

Tests/Fixtures/OptionalParameter.php

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

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

Tests/Fixtures/includes/autowiring_classes.php

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

121121
class E
122122
{
123-
public function __construct(D $d = null)
123+
public function __construct(?D $d = null)
124124
{
125125
}
126126
}
@@ -176,13 +176,6 @@ public function __construct(Dunglas $j, Dunglas $k)
176176
}
177177
}
178178

179-
class OptionalParameter
180-
{
181-
public function __construct(CollisionInterface $c = null, A $a, Foo $f = null)
182-
{
183-
}
184-
}
185-
186179
class BadTypeHintedArgument
187180
{
188181
public function __construct(Dunglas $k, NotARealClass $r)
@@ -216,7 +209,7 @@ public function __construct(A $k, $foo, Dunglas $dunglas, array $bar)
216209

217210
class MultipleArgumentsOptionalScalar
218211
{
219-
public function __construct(A $a, $foo = 'default_val', Lille $lille = null)
212+
public function __construct(A $a, $foo = 'default_val', ?Lille $lille = null)
220213
{
221214
}
222215
}
@@ -240,7 +233,7 @@ public function __construct(
240233
*/
241234
class ClassForResource
242235
{
243-
public function __construct($foo, Bar $bar = null)
236+
public function __construct($foo, ?Bar $bar = null)
244237
{
245238
}
246239

@@ -455,7 +448,7 @@ public function setBar()
455448
{
456449
}
457450

458-
public function setOptionalNotAutowireable(NotARealClass $n = null)
451+
public function setOptionalNotAutowireable(?NotARealClass $n = null)
459452
{
460453
}
461454

@@ -513,7 +506,7 @@ class DecoratorImpl implements DecoratorInterface
513506

514507
class Decorated implements DecoratorInterface
515508
{
516-
public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = [])
509+
public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?DecoratorInterface $decorated = null, array $foo = [])
517510
{
518511
}
519512
}

0 commit comments

Comments
 (0)