Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 5.4:
  Make more nullable types explicit
  Add more explicit nullable types for default null values
  • Loading branch information
derrabus committed Mar 19, 2024
2 parents bfe8779 + 0ba1fa4 commit c8d73fd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Tests/Compiler/AutowirePassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
use Symfony\Component\DependencyInjection\Tests\Fixtures\OptionalParameter;
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTargetAnonymous;
use Symfony\Component\DependencyInjection\TypedReference;
Expand Down Expand Up @@ -405,6 +406,9 @@ public function testResolveParameter()
$this->assertEquals(Foo::class, $container->getDefinition('bar')->getArgument(0));
}

/**
* @group legacy
*/
public function testOptionalParameter()
{
$container = new ContainerBuilder();
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class Bar implements BarInterface
{
public $quz;

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

public static function create(\NonExistent $nonExistent = null, $factory = null)
public static function create(?\NonExistent $nonExistent = null, $factory = null)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function setFoosVariadic(Foo $foo, Foo ...$foos)
$this->foo = $foo;
}

public function setFoosOptional(Foo $foo, Foo $fooOptional = null)
public function setFoosOptional(Foo $foo, ?Foo $fooOptional = null)
{
$this->foo = $foo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BarOptionalArgument
{
public $foo;

public function __construct(\stdClass $foo = null)
public function __construct(?\stdClass $foo = null)
{
$this->foo = $foo;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/CheckTypeDeclarationsPass/Foo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static function createBar()
return new Bar(new \stdClass());
}

public static function createBarArguments(\stdClass $stdClass, \stdClass $stdClassOptional = null)
public static function createBarArguments(\stdClass $stdClass, ?\stdClass $stdClassOptional = null)
{
return new Bar($stdClass);
}
Expand Down
23 changes: 23 additions & 0 deletions Tests/Fixtures/OptionalParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;

use Symfony\Component\DependencyInjection\Tests\Compiler\A;
use Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface;
use Symfony\Component\DependencyInjection\Tests\Compiler\Foo;

class OptionalParameter
{
public function __construct(?CollisionInterface $c = null, A $a, ?Foo $f = null)
{
}
}
2 changes: 1 addition & 1 deletion Tests/Fixtures/Prototype/Foo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#[When(env: 'dev')]
class Foo implements FooInterface, Sub\BarInterface
{
public function __construct($bar = null, iterable $foo = null, object $baz = null)
public function __construct($bar = null, ?iterable $foo = null, ?object $baz = null)
{
}

Expand Down
17 changes: 5 additions & 12 deletions Tests/Fixtures/includes/autowiring_classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function __construct(A $a, DInterface $d)

class E
{
public function __construct(D $d = null)
public function __construct(?D $d = null)
{
}
}
Expand Down Expand Up @@ -176,13 +176,6 @@ public function __construct(Dunglas $j, Dunglas $k)
}
}

class OptionalParameter
{
public function __construct(CollisionInterface $c = null, A $a, Foo $f = null)
{
}
}

class BadTypeHintedArgument
{
public function __construct(Dunglas $k, NotARealClass $r)
Expand Down Expand Up @@ -216,7 +209,7 @@ public function __construct(A $k, $foo, Dunglas $dunglas, array $bar)

class MultipleArgumentsOptionalScalar
{
public function __construct(A $a, $foo = 'default_val', Lille $lille = null)
public function __construct(A $a, $foo = 'default_val', ?Lille $lille = null)
{
}
}
Expand All @@ -240,7 +233,7 @@ public function __construct(
*/
class ClassForResource
{
public function __construct($foo, Bar $bar = null)
public function __construct($foo, ?Bar $bar = null)
{
}

Expand Down Expand Up @@ -455,7 +448,7 @@ public function setBar()
{
}

public function setOptionalNotAutowireable(NotARealClass $n = null)
public function setOptionalNotAutowireable(?NotARealClass $n = null)
{
}

Expand Down Expand Up @@ -513,7 +506,7 @@ class DecoratorImpl implements DecoratorInterface

class Decorated implements DecoratorInterface
{
public function __construct($quz = null, \NonExistent $nonExistent = null, DecoratorInterface $decorated = null, array $foo = [])
public function __construct($quz = null, ?\NonExistent $nonExistent = null, ?DecoratorInterface $decorated = null, array $foo = [])
{
}
}
Expand Down

0 comments on commit c8d73fd

Please sign in to comment.