8000 minor #20153 [VarDumper] Fix ReflectionNamedType->getName() detection… · symfony/symfony@31a68b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31a68b8

Browse files
minor #20153 [VarDumper] Fix ReflectionNamedType->getName() detection (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] Fix ReflectionNamedType->getName() detection | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - There is no side effect to this patch, except that __toString were still used, whereas getName should have been (both methods return the same, but __toString is deprecated since 7.1). I somehow missed that getName was on a new `ReflectionNamedType` class... Commits ------- dda18df [VarDumper] Fix ReflectionNamedType->getName() detection
2 parents f03c95c + dda18df commit 31a68b8

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