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 812bf5c

Browse filesBrowse files
[VarDumper] Fix dumping type hints for non-existing parent classes
1 parent 44efeaa commit 812bf5c
Copy full SHA for 812bf5c

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+16
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php
+5-6Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
+4-3Lines 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
}
+7Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.