[VarDumper] Fix dumping type hints for non-existing parent classes

This commit is contained in:
Nicolas Grekas 2016-04-19 19:21:45 +02:00
parent 44efeaaa27
commit 812bf5c45d
3 changed files with 16 additions and 9 deletions

View File

@ -171,12 +171,11 @@ class ReflectionCaster
if ($c->hasType()) { if ($c->hasType()) {
$a[$prefix.'typeHint'] = $c->getType()->__toString(); $a[$prefix.'typeHint'] = $c->getType()->__toString();
} }
} elseif ($c->isArray()) { } else {
$a[$prefix.'typeHint'] = 'array'; $v = explode(' ', $c->__toString(), 6);
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) { if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
$a[$prefix.'typeHint'] = 'callable'; $a[$prefix.'typeHint'] = $v[4];
} elseif ($v = $c->getClass()) { }
$a[$prefix.'typeHint'] = $v->name;
} }
} catch (\ReflectionException $e) { } catch (\ReflectionException $e) {
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) { if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\VarDumper\Tests\Caster; namespace Symfony\Component\VarDumper\Tests\Caster;
use Symfony\Component\VarDumper\Test\VarDumperTestCase; use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
/** /**
* @author Nicolas Grekas <p@tchwork.com> * @author Nicolas Grekas <p@tchwork.com>
@ -47,7 +48,7 @@ ReflectionClass {
"export" => ReflectionMethod { "export" => ReflectionMethod {
+name: "export" +name: "export"
+class: "ReflectionClass" +class: "ReflectionClass"
parameters: array:2 [ %A parameters: array:2 [
"$%s" => ReflectionParameter { "$%s" => ReflectionParameter {
%A position: 0 %A position: 0
%A } %A }
@ -70,7 +71,7 @@ EOTXT
ReflectionParameter { ReflectionParameter {
+name: "arg1" +name: "arg1"
position: 0 position: 0
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass" typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
default: null default: null
} }
EOTXT EOTXT
@ -121,6 +122,6 @@ EOTXT
} }
} }
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2) function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)
{ {
} }

View File

@ -0,0 +1,7 @@
<?php
namespace Symfony\Component\VarDumper\Tests\Fixtures;
class NotLoadableClass extends NotLoadableClass
{
}