8000 [VarDumper] Fix casting for ReflectionParameter · symfony/symfony@4b88aca · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b88aca

Browse files
[VarDumper] Fix casting for ReflectionParameter
1 parent c24ca43 commit 4b88aca

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172, 10000 6 +172,9 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
172172
$a[$prefix.'typeHint'] = $v->name;
173173
}
174174
} catch (\ReflectionException $e) {
175+
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
176+
$a[$prefix.'typeHint'] = $m[1];
177+
}
175178
}
176179

177180
try {
@@ -180,6 +183,9 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
180183
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
181184
}
182185
} catch (\ReflectionException $e) {
186+
if (isset($a[$prefix.'typeHint']) && $c->allowsNull()) {
187+
$a[$prefix.'default'] = null;
188+
}
183189
}
184190

185191
return $a;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ public function testReflectionCaster()
6161
);
6262
}
6363

64+
public function testReflectionParameter()
65+
{
66+
$var = new \ReflectionParameter(__NAMESPACE__.'\reflectionParameterFixture', 0);
67+
68+
$this->assertDumpMatchesFormat(
69+
<<<'EOTXT'
70+
ReflectionParameter {
71+
+name: "arg1"
72+
position: 0
73+
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
74+
default: null
75+
}
76+
EOTXT
77+
, $var
78+
);
79+
}
80+
6481
/**
6582
* @requires PHP 7.0
6683
*/
@@ -82,3 +99,7 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
8299
);
83100
}
84101
}
102+
103+
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
104+
{
105+
}

src/Symfony/Component/VarDumper/Tests/Test/VarDumpTestTraitTest.php renamed to src/Symfony/Component/VarDumper/Tests/Test/VarDumperTestTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
// Skipping trait tests for PHP < 5.4
13-
if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
14-
require 'VarDumpTestTraitRequire54.php';
13+
if (PHP_VERSION_ID >= 50400) {
14+
require __DIR__.'/VarDumperTestTraitRequire54.php';
1515
}
1616

0 commit comments

Comments
 (0)
0