Skip to content

Commit 0edc63b

Browse files
Merge branch '6.2' into 6.3
* 6.2: [GHA] Remove deprecations-baseline [DependencyInjection] Support PHP 8.2 `true` type
2 parents 0da7fa5 + 739a34b commit 0edc63b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ private function checkType(Definition $checkedDefinition, mixed $value, \Reflect
311311
if (false === $value) {
312312
return;
313313
}
314+
} elseif ('true' === $type) {
315+
if (true === $value) {
316+
return;
317+
}
314318
} elseif ($reflectionType->isBuiltin()) {
315319
$checkFunction = sprintf('is_%s', $type);
316320
if ($checkFunction($value)) {

Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
3333
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\IntersectionConstructor;
3434
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor;
35+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructorPHP82;
3536
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo;
3637
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\WaldoFoo;
3738
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Wobble;
@@ -859,6 +860,26 @@ public function testUnionTypePassesWithFalse()
859860
$this->addToAssertionCount(1);
860861
}
861862

863+
/**
864+
* @requires PHP 8.2
865+
*/
866+
public function testUnionTypePassesWithTrue()
867+
{
868+
$container = new ContainerBuilder();
869+
870+
$container->register('unionTrue', UnionConstructorPHP82::class)
871+
->setFactory([UnionConstructorPHP82::class, 'createTrue'])
872+
->setArguments([true]);
873+
874+
$container->register('unionNull', UnionConstructorPHP82::class)
875+
->setFactory([UnionConstructorPHP82::class, 'createNull'])
876+
->setArguments([null]);
877+
878+
(new CheckTypeDeclarationsPass(true))->process($container);
879+
880+
$this->addToAssertionCount(1);
881+
}
882+
862883
public function testUnionTypeFailsWithReference()
863884
{
864885
$container = new ContainerBuilder();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
4+
5+
class UnionConstructorPHP82
6+
{
7+
public static function createTrue(array|true $arg): static
8+
{
9+
return new static(0);
10+
}
11+
12+
public static function createNull(null $arg): static
13+
{
14+
return new static(0);
15+
}
16+
}

0 commit comments

Comments
 (0)