Fix NameResolver for parameters without typehints

This commit is contained in:
nikic 2011-11-06 17:16:40 +01:00
parent b84553e011
commit d9452e611a

View File

@ -51,22 +51,23 @@ class PHPParser_NodeVisitor_NameResolver extends PHPParser_NodeVisitorAbstract
|| $node instanceof PHPParser_Node_Expr_New || $node instanceof PHPParser_Node_Expr_New
|| $node instanceof PHPParser_Node_Expr_Instanceof || $node instanceof PHPParser_Node_Expr_Instanceof
) { ) {
$node->class = $this->resolveClassName($node->class); if ($node->class instanceof PHPParser_Node_Name) {
$node->class = $this->resolveClassName($node->class);
}
} elseif ($node instanceof PHPParser_Node_Expr_FuncCall } elseif ($node instanceof PHPParser_Node_Expr_FuncCall
|| $node instanceof PHPParser_Node_Expr_ConstFetch || $node instanceof PHPParser_Node_Expr_ConstFetch
) { ) {
$node->name = $this->resolveOtherName($node->name); if ($node->name instanceof PHPParser_Node_Name) {
} elseif ($node instanceof PHPParser_Node_Param) { $node->name = $this->resolveOtherName($node->name);
}
} elseif ($node instanceof PHPParser_Node_Param
&& $node instanceof PHPParser_Node_Name
) {
$node->type = $this->resolveClassName($node->type); $node->type = $this->resolveClassName($node->type);
} }
} }
protected function resolveClassName(PHPParser_Node $name) { protected function resolveClassName(PHPParser_Node_Name $name) {
// can't resolve dynamic names at compile-time
if (!$name instanceof PHPParser_Node_Name) {
return $name;
}
// don't resolve special class names // don't resolve special class names
if (in_array((string) $name, array('self', 'parent', 'static'))) { if (in_array((string) $name, array('self', 'parent', 'static'))) {
return $name; return $name;
@ -88,12 +89,7 @@ class PHPParser_NodeVisitor_NameResolver extends PHPParser_NodeVisitorAbstract
return new PHPParser_Node_Name_FullyQualified($name->parts); return new PHPParser_Node_Name_FullyQualified($name->parts);
} }
protected function resolveOtherName(PHPParser_Node $name) { protected function resolveOtherName(PHPParser_Node_Name $name) {
// can't resolve dynamic names at compile-time
if (!$name instanceof PHPParser_Node_Name) {
return $name;
}
// fully qualified names are already resolved and we can't do anything about unqualified // fully qualified names are already resolved and we can't do anything about unqualified
// ones at compiler-time // ones at compiler-time
if ($name->isFullyQualified() || $name->isUnqualified()) { if ($name->isFullyQualified() || $name->isUnqualified()) {