8000 bug #42099 [VarDumper] Support for intersection types (derrabus) · Seldaek/symfony@b1fbd1b · GitHub
[go: up one dir, main page]

Skip to content

Commit b1fbd1b

Browse files
bug symfony#42099 [VarDumper] Support for intersection types (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [VarDumper] Support for intersection types | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | symfony#41552 | License | MIT | Doc PR | N/A Commits ------- 3cf1057 [VarDumper] Support for intersection types
2 parents e5c96c4 + 3cf1057 commit b1fbd1b

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

.github/patch-types.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php'):
4343
case false !== strpos($file, '/src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectOuter.php'):
4444
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
45+
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionIntersectionTypeFixture.php'):
4546
continue 2;
4647
}
4748

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, $isNes
102102
$prefix.'allowsNull' => $c->allowsNull(),
103103
$prefix.'isBuiltin' => $c->isBuiltin(),
104104
];
105-
} elseif ($c instanceof \ReflectionUnionType) {
105+
} elseif ($c instanceof \ReflectionUnionType || $c instanceof \ReflectionIntersectionType) {
106106
$a[$prefix.'allowsNull'] = $c->allowsNull();
107107
self::addMap($a, $c, [
108108
'types' => 'getTypes',

src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\VarDumper\Tests\Fixtures\ExtendsReflectionTypeFixture;
1818
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
1919
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
20+
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionIntersectionTypeFixture;
2021
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionNamedTypeFixture;
2122
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionUnionTypeFixture;
2223

@@ -78,7 +79,7 @@ public function testClosureCaster()
7879
$b: & 123
7980
}
8081
file: "%sReflectionCasterTest.php"
81-
line: "71 to 71"
82+
line: "72 to 72"
8283
}
8384
EOTXT
8485
, $var
@@ -228,6 +229,26 @@ public function testReflectionParameterNullableUnion()
228229
);
229230
}
230231

232+
/**
233+
* @requires PHP 8.1
234+
*/
235+
public function testReflectionParameterIntersection()
236+
{
237+
$f = eval('return function (Traversable&Countable $a) {};');
238+
$var = new \ReflectionParameter($f, 0);
239+
240+
$this->assertDumpMatchesFormat(
241+
<<<'EOTXT'
242+
ReflectionParameter {
243+
+name: "a"
244+
position: 0
245+
typeHint: "Traversable&Countable"
246+
}
247+
EOTXT
248+
, $var
249+
);
250+
}
251+
231252
/**
232253
* @requires PHP 7.4
233254
*/
@@ -292,6 +313,34 @@ public function testReflectionUnionType()
292313
);
293314
}
294315

316+
/**
317+
* @requires PHP 8.1
318+
*/
319+
public function testReflectionIntersectionType()
320+
{
321+
$var = (new \ReflectionProperty(ReflectionIntersectionTypeFixture::class, 'a'))->getType();
322+
$this->assertDumpMatchesFormat(
323+
<<<'EOTXT'
324+
ReflectionIntersectionType {
325+
allowsNull: false
326+
types: array:2 [
327+
0 => ReflectionNamedType {
328+
name: "Traversable"
329+
allowsNull: false
330+
isBuiltin: false
331+
}
332+
1 => ReflectionNamedType {
333+
name: "Countable"
334+
allowsNull: false
335+
isBuiltin: false
336+
}
337+
]
338+
}
339+
EOTXT
340+
, $var
341+
);
342+
}
343+
295344
/**
296345
* @requires PHP 8
297346
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class ReflectionIntersectionTypeFixture
6+
{
7+
public \Traversable&\Countable $a;
8+
}

0 commit comments

Comments
 (0)
0