Skip to content

Commit ed1860e

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: Make more nullable types explicit Add more explicit nullable types for default null values
2 parents 84aa015 + c8d73fd commit ed1860e

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
@@ -34,6 +34,7 @@
3434
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface;
3535
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
3636
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
37+
use Symfony\Component\DependencyInjection\Tests\Fixtures\OptionalParameter;
3738
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
3839
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTargetAnonymous;
3940
use Symfony\Component\DependencyInjection\TypedReference;
@@ -399,6 +400,9 @@ public function testResolveParameter()
399400
$this->assertEquals(Foo::class, $container->getDefinition('bar')->getArgument(0));
400401
}
401402

403+
/**
404+
* @group legacy
405+
*/
402406
public function testOptionalParameter()
403407
{
404408
$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
@@ -106,7 +106,7 @@ public function __construct(A $a, DInterface $d)
106106

107107
class E
108108
{
109-
public function __construct(D $d = null)
109+
public function __construct(?D $d = null)
110110
{
111111
}
112112
}
@@ -162,13 +162,6 @@ public function __construct(Dunglas $j, Dunglas $k)
162162
}
163163
}
164164

165-
class OptionalParameter
166-
{
167-
public function __construct(CollisionInterface $c = null, A $a, Foo $f = null)
168-
{
169-
}
170-
}
171-
172165
class BadTypeHintedArgument
173166
{
174167
public function __construct(Dunglas $k, NotARealClass $r)
@@ -202,7 +195,7 @@ public function __construct(A $k, $foo, Dunglas $dunglas, array $bar)
202195

203196
class MultipleArgumentsOptionalScalar
204197
{
205-
public function __construct(A $a, $foo = 'default_val', Lille $lille = null)
198+
public function __construct(A $a, $foo = 'default_val', ?Lille $lille = null)
206199
{
207200
}
208201
}
@@ -226,7 +219,7 @@ public function __construct(
226219
*/
227220
class ClassForResource
228221
{
229-
public function __construct($foo, Bar $bar = null)
222+
public function __construct($foo, ?Bar $bar = null)
230223
{
231224
}
232225

@@ -345,7 +338,7 @@ public function setBar()
345338
{
346339
}
347340

348-
public function setOptionalNotAutowireable(NotARealClass $n = null)
341+
public function setOptionalNotAutowireable(?NotARealClass $n = null)
349342
{
350343
}
351344

@@ -392,7 +385,7 @@ class DecoratorImpl implements DecoratorInterface
392385

393386
class Decorated implements DecoratorInterface
394387
{
395-
public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = [])
388+
public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?DecoratorInterface $decorated = null, array $foo = [])
396389
{
397390
}
398391
}

0 commit comments

Comments
 (0)