1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-20 04:36:57 +01:00

Make NameResolver resolve trait alias and precedence names

This commit is contained in:
Arne Blankerts 2014-11-03 16:06:43 +01:00 committed by nikic
parent b9a60372f2
commit 6fad8ff32a
3 changed files with 33 additions and 8 deletions

View File

@ -2,8 +2,12 @@
namespace PhpParser\Node\Stmt;
use PhpParser\Node\Stmt;
use PhpParser\Node;
abstract class TraitUseAdaptation extends Stmt
/**
* @property Node\Name $trait Trait name
* @property string $method Method name
*/
abstract class TraitUseAdaptation extends Node\Stmt
{
}

View File

@ -77,6 +77,19 @@ class NameResolver extends NodeVisitorAbstract
foreach ($node->traits as &$trait) {
$trait = $this->resolveClassName($trait);
}
foreach($node->adaptations as $adaptation) {
if (null !== $adaptation->trait) {
$adaptation->trait = $this->resolveClassName($adaptation->trait);
}
if ($adaptation instanceof Stmt\TraitUseAdaptation\Precedence) {
foreach ($adaptation->insteadof as &$insteadof) {
$insteadof = $this->resolveClassName($insteadof);
}
}
}
} elseif ($node instanceof Node\Param
&& $node->type instanceof Name
) {

View File

@ -144,11 +144,15 @@ EOC;
<?php
namespace NS;
class A extends B implements C {
use A;
class A extends B implements C, D {
use E, F, G {
f as private g;
E::h as i;
E::j insteadof F, G;
}
}
interface A extends C {
interface A extends C, D {
public function a(A $a);
}
@ -170,11 +174,15 @@ EOC;
$expectedCode = <<<'EOC'
namespace NS;
class A extends \NS\B implements \NS\C
class A extends \NS\B implements \NS\C, \NS\D
{
use \NS\A;
use \NS\E, \NS\F, \NS\G {
f as private g;
\NS\E::h as i;
\NS\E::j insteadof \NS\F, \NS\G;
}
}
interface A extends \NS\C
interface A extends \NS\C, \NS\D
{
public function a(\NS\A $a);
}