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
This commit is contained in:
commit
31a68b8bef
@ -115,7 +115,8 @@ class ReflectionCaster
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (isset($a[$prefix.'returnType'])) {
|
if (isset($a[$prefix.'returnType'])) {
|
||||||
$a[$prefix.'returnType'] = method_exists('ReflectionType', 'getName') ? $a[$prefix.'returnType']->getName() : $a[$prefix.'returnType']->__toString();
|
$v = $a[$prefix.'returnType'];
|
||||||
|
$a[$prefix.'returnType'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||||
}
|
}
|
||||||
if (isset($a[$prefix.'this'])) {
|
if (isset($a[$prefix.'this'])) {
|
||||||
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
|
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
|
||||||
@ -168,9 +169,9 @@ class ReflectionCaster
|
|||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (method_exists($c, 'hasType')) {
|
if (method_exists($c, 'getType')) {
|
||||||
if ($c->hasType()) {
|
if ($v = $c->getType()) {
|
||||||
$a[$prefix.'typeHint'] = method_exists('ReflectionType', 'getName') ? $c->getType()->getName() : $c->getType()->__toString();
|
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$v = explode(' ', $c->__toString(), 6);
|
$v = explode(' ', $c->__toString(), 6);
|
||||||
@ -196,7 +197,7 @@ class ReflectionCaster
|
|||||||
unset($a[$prefix.'allowsNull']);
|
unset($a[$prefix.'allowsNull']);
|
||||||
}
|
}
|
||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
if (isset($a[$prefix.'typeHint']) && $c->allowsNull() && !method_exists('ReflectionType', 'getName')) {
|
if (isset($a[$prefix.'typeHint']) && $c->allowsNull() && !class_exists('ReflectionNamedType', false)) {
|
||||||
$a[$prefix.'default'] = null;
|
$a[$prefix.'default'] = null;
|
||||||
unset($a[$prefix.'allowsNull']);
|
unset($a[$prefix.'allowsNull']);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user