[VarDumper] Support for intersection types
Signed-off-by: Alexander M. Turek <me@derrabus.de>
This commit is contained in:
parent
3b21091cce
commit
3cf105766a
1
.github/patch-types.php
vendored
1
.github/patch-types.php
vendored
@ -41,6 +41,7 @@ foreach ($loader->getClassMap() as $class => $file) {
|
||||
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php'):
|
||||
case false !== strpos($file, '/src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectOuter.php'):
|
||||
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
|
||||
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionIntersectionTypeFixture.php'):
|
||||
continue 2;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class ReflectionCaster
|
||||
$prefix.'allowsNull' => $c->allowsNull(),
|
||||
$prefix.'isBuiltin' => $c->isBuiltin(),
|
||||
];
|
||||
} elseif ($c instanceof \ReflectionUnionType) {
|
||||
} elseif ($c instanceof \ReflectionUnionType || $c instanceof \ReflectionIntersectionType) {
|
||||
$a[$prefix.'allowsNull'] = $c->allowsNull();
|
||||
self::addMap($a, $c, [
|
||||
'types' => 'getTypes',
|
||||
|
@ -17,6 +17,7 @@ use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\ExtendsReflectionTypeFixture;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionIntersectionTypeFixture;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionNamedTypeFixture;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionUnionTypeFixture;
|
||||
|
||||
@ -78,7 +79,7 @@ Closure($x) {
|
||||
$b: & 123
|
||||
}
|
||||
file: "%sReflectionCasterTest.php"
|
||||
line: "71 to 71"
|
||||
line: "72 to 72"
|
||||
}
|
||||
EOTXT
|
||||
, $var
|
||||
@ -228,6 +229,26 @@ EOTXT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 8.1
|
||||
*/
|
||||
public function testReflectionParameterIntersection()
|
||||
{
|
||||
$f = eval('return function (Traversable&Countable $a) {};');
|
||||
$var = new \ReflectionParameter($f, 0);
|
||||
|
||||
$this->assertDumpMatchesFormat(
|
||||
<<<'EOTXT'
|
||||
ReflectionParameter {
|
||||
+name: "a"
|
||||
position: 0
|
||||
typeHint: "Traversable&Countable"
|
||||
}
|
||||
EOTXT
|
||||
, $var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.4
|
||||
*/
|
||||
@ -292,6 +313,34 @@ EOTXT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 8.1
|
||||
*/
|
||||
public function testReflectionIntersectionType()
|
||||
{
|
||||
$var = (new \ReflectionProperty(ReflectionIntersectionTypeFixture::class, 'a'))->getType();
|
||||
$this->assertDumpMatchesFormat(
|
||||
<<<'EOTXT'
|
||||
ReflectionIntersectionType {
|
||||
allowsNull: false
|
||||
types: array:2 [
|
||||
0 => ReflectionNamedType {
|
||||
name: "Traversable"
|
||||
allowsNull: false
|
||||
isBuiltin: false
|
||||
}
|
||||
1 => ReflectionNamedType {
|
||||
name: "Countable"
|
||||
allowsNull: false
|
||||
isBuiltin: false
|
||||
}
|
||||
]
|
||||
}
|
||||
EOTXT
|
||||
, $var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 8
|
||||
*/
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests\Fixtures;
|
||||
|
||||
class ReflectionIntersectionTypeFixture
|
||||
{
|
||||
public \Traversable&\Countable $a;
|
||||
}
|
Reference in New Issue
Block a user