10000 bug #18593 [VarDumper] Fix dumping type hints for non-existing parent… · symfony/symfony@6a0a687 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a0a687

Browse files
bug #18593 [VarDumper] Fix dumping type hints for non-existing parent classes (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] Fix dumping type hints for non-existing parent classes | 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 | - Commits ------- 812bf5c [VarDumper] Fix dumping type hints for non-existing parent classes
2 parents 2f0b8f8 + 812bf5c commit 6a0a687

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,11 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
171171
if ($c->hasType()) {
172172
$a[$prefix.'typeHint'] = $c->getType()->__toString();
173173
}
174-
} elseif ($c->isArray()) {
175-
$a[$prefix.'typeHint'] = 'array';
176-
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
177-
$a[$prefix.'typeHint'] = 'callable';
178-
} elseif ($v = $c->getClass()) {
179-
$a[$prefix.'typeHint'] = $v->name;
174+
} else {
175+
$v = explode(' ', $c->__toString(), 6);
176+
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
177+
$a[$prefix.'typeHint'] = $v[4];
178+
}
180179
}
181180
} catch (\ReflectionException $e) {
182181
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

1414
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
15+
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
1516

1617
/**
1718
* @author Nicolas Grekas <p@tchwork.com>
@@ -47,7 +48,7 @@ public function testReflectionCaster()
4748
"export" => ReflectionMethod {
4849
+name: "export"
4950
+class: "ReflectionClass"
50-
parameters: array:2 [
51+
%A parameters: array:2 [
5152
"$%s" => ReflectionParameter {
5253
%A position: 0
5354
%A }
@@ -70,7 +71,7 @@ public function testReflectionParameter()
7071
ReflectionParameter {
7172
+name: "arg1"
7273
position: 0
73-
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
74+
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
7475
default: null
7576
}
7677
EOTXT
@@ -121,6 +122,6 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
121122
}
122123
}
123124

124-
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
125+
function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)
125126
{
126127
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class NotLoadableClass extends NotLoadableClass
6+
{
7+
}

0 commit comments

Comments
 (0)
0