8000 [VarDumper] Fix ReflectionNamedType->getName() detection · symfony/symfony@dda18df · GitHub
[go: up one dir, main page]

Skip to content

Commit dda18df

Browse files
[VarDumper] Fix ReflectionNamedType->getName() detection
1 parent 3086fd3 commit dda18df

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
115115
));
116116

117117
if (isset($a[$prefix.'returnType'])) {
118-
$a[$prefix.'returnType'] = method_exists('ReflectionType', 'getName') ? $a[$prefix.'returnType']->getName() : $a[$prefix.'returnType']->__toString();
118+
$v = $a[$prefix.'returnType'];
119+
$a[$prefix.'returnType'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
119120
}
120121
if (isset($a[$prefix.'this'])) {
121122
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
@@ -168,9 +169,9 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
168169
));
169170

170171
try {
171-
if (method_exists($c, 'hasType')) {
172-
if ($c->hasType()) {
173-
$a[$prefix.'typeHint'] = method_exists('ReflectionType', 'getName') ? $c->getType()->getName() : $c->getType()->__toString();
172+
if (method_exists($c, 'getType')) {
173+
if ($v = $c->getType()) {
174+
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
174175
}
175176
} else {
176177
$v = explode(' ', $c->__toString(), 6);
@@ -196,7 +197,7 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
196197
unset($a[$prefix.'allowsNull']);
197198
}
198199
} catch (\ReflectionException $e) {
199-
if (isset($a[$prefix.'typeHint']) && $c->allowsNull() && !method_exists('ReflectionType', 'getName')) {
200+
if (isset($a[$prefix.'typeHint']) && $c->allowsNull() && !class_exists('ReflectionNamedType', false)) {
200201
$a[$prefix.'default'] = null;
201202
unset($a[$prefix.'allowsNull']);
202203
}

0 commit comments

Comments
 (0)
0