Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 39d4b45

Browse filesBrowse files
committed
This commit, adds extended reflectiontype support and removes a very very small possibility for a bc break in versions < 8
1 parent 05cef79 commit 39d4b45
Copy full SHA for 39d4b45

File tree

Expand file treeCollapse file tree

3 files changed

+66
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+66
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, $isNes
9696
{
9797
$prefix = Caster::PREFIX_VIRTUAL;
9898

99-
if ($c instanceof \ReflectionUnionType) {
100-
$a[$prefix.'allowsNull'] = $c->allowsNull();
101-
self::addMap($a, $c, [
102-
'types' => 'getTypes',
103-
]);
104-
} elseif ($c instanceof \ReflectionNamedType) {
99+
if ($c instanceof \ReflectionNamedType || \PHP_VERSION_ID < 80000) {
105100
$a += [
106-
$prefix.'name' => $c->getName(),
101+
$prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : (string) $c,
107102
$prefix.'allowsNull' => $c->allowsNull(),
108103
$prefix.'isBuiltin' => $c->isBuiltin(),
109104
];
105+
} elseif ($c instanceof \ReflectionUnionType) {
106+
$a[$prefix . 'allowsNull'] = $c->allowsNull();
107+
self::addMap($a, $c, [
108+
'types' => 'getTypes',
109+
]);
110110
} else {
111-
// As of PHP 8.0 there are only two children of ReflectionType (abstract) so this is unreachable.
111+
//Userland may extend reflection type.
112112
$a[$prefix.'allowsNull'] = $c->allowsNull();
113113
}
114114

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarDumper\Caster\Caster;
1616
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
17+
use Symfony\Component\VarDumper\Tests\Fixtures\ExtendsReflectionTypeFixture;
1718
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
1819
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
1920
use Symfony\Component\VarDumper\Tests\Fixtures\ReflectionNamedTypeFixture;
@@ -77,7 +78,7 @@ public function testClosureCaster()
7778
$b: & 123
7879
}
7980
file: "%sReflectionCasterTest.php"
80-
line: "70 to 70"
81+
line: "71 to 71"
8182
}
8283
EOTXT
8384
, $var
@@ -277,6 +278,40 @@ public function testReflectionUnionType()
277278
);
278279
}
279280

281+
/**
282+
* @requires PHP 8
283+
*/
284+
public function testExtendsReflectionType()
285+
{
286+
$var = new ExtendsReflectionTypeFixture();
287+
$this->assertDumpMatchesFormat(
288+
<<<'EOTXT'
289+
Symfony\Component\VarDumper\Tests\Fixtures\ExtendsReflectionTypeFixture {
290+
allowsNull: false
291+
}
292+
EOTXT
293+
, $var
294+
);
295+
}
296+
297+
/**
298+
* @requires PHP < 8
299+
*/
300+
public function testLegacyExtendsReflectionType()
301+
{
302+
$var = new ExtendsReflectionTypeFixture();
303+
$this->assertDumpMatchesFormat(
304+
<<<'EOTXT'
305+
Symfony\Component\VarDumper\Tests\Fixtures\ExtendsReflectionTypeFixture {
306+
name: "fake"
307+
allowsNull: false
308+
isBuiltin: false
309+
}
310+
EOTXT
311+
, $var
312+
);
313+
}
314+
280315
public function testReturnType()
281316
{
282317
$f = eval('return function ():int {};');
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
4+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
5+
6+
class ExtendsReflectionTypeFixture extends \ReflectionType
7+
{
8+
public function allowsNull()
9+
{
10+
return false;
11+
}
12+
13+
public function isBuiltin()
14+
{
15+
return false;
16+
}
17+
18+
public function __toString()
19+
{
20+
return 'fake';
21+
}
22+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.