@@ 35-58 (lines=24) @@ | ||
32 | * namespace Humbug\Foo; |
|
33 | * ``` |
|
34 | */ |
|
35 | final class ScopeNamespaceStmtNodeVisitor extends NodeVisitorAbstract |
|
36 | { |
|
37 | private $prefix; |
|
38 | ||
39 | public function __construct(string $prefix) |
|
40 | { |
|
41 | $this->prefix = $prefix; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @inheritdoc |
|
46 | */ |
|
47 | public function enterNode(Node $node): Node |
|
48 | { |
|
49 | if ($node instanceof Namespace_ |
|
50 | && null !== $node->name |
|
51 | && $this->prefix !== $node->name->getFirst() |
|
52 | ) { |
|
53 | $node->name = Name::concat($this->prefix, $node->name); |
|
54 | } |
|
55 | ||
56 | return $node; |
|
57 | } |
|
58 | } |
|
59 |
@@ 35-57 (lines=23) @@ | ||
32 | * use Humbug\Foo{X,Y}; |
|
33 | * ``` |
|
34 | */ |
|
35 | final class ScopeGroupUseStmtNodeVisitor extends NodeVisitorAbstract |
|
36 | { |
|
37 | private $prefix; |
|
38 | ||
39 | public function __construct(string $prefix) |
|
40 | { |
|
41 | $this->prefix = $prefix; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @inheritdoc |
|
46 | */ |
|
47 | public function enterNode(Node $node): Node |
|
48 | { |
|
49 | if ($node instanceof GroupUse |
|
50 | && $this->prefix !== $node->prefix->getFirst() |
|
51 | ) { |
|
52 | $node->prefix = Name::concat($this->prefix, $node->prefix); |
|
53 | } |
|
54 | ||
55 | return $node; |
|
56 | } |
|
57 | } |
|
58 |