1 | <?php |
||
29 | final class NamespaceStmtCollection implements IteratorAggregate, Countable |
||
30 | { |
||
31 | /** |
||
32 | * @var Namespace_[] |
||
33 | */ |
||
34 | private $nodes = []; |
||
35 | |||
36 | /** |
||
37 | * @var Name|null[] Associative array with the potentially prefixed namespace names as keys and their original name |
||
38 | * as value. |
||
39 | */ |
||
40 | private $mapping = []; |
||
41 | |||
42 | /** |
||
43 | * @param Namespace_ $node New namespace, may have been prefixed. |
||
44 | * @param Namespace_ $originalName Original unchanged namespace. |
||
45 | */ |
||
46 | 335 | public function add(Namespace_ $node, Namespace_ $originalName) |
|
52 | |||
53 | 173 | public function findNamespaceForNode(Node $node): ?Name |
|
54 | { |
||
55 | 173 | if (0 === count($this->nodes)) { |
|
56 | return null; |
||
57 | } |
||
58 | |||
59 | // Shortcut if there is only one namespace |
||
60 | 173 | if (1 === count($this->nodes)) { |
|
61 | 104 | return $this->nodes[0]->name; |
|
62 | } |
||
63 | |||
64 | 86 | return $this->getNodeNamespace($node); |
|
65 | } |
||
66 | |||
67 | 195 | public function getCurrentNamespaceName(): ?Name |
|
68 | { |
||
69 | 195 | if (0 === count($this->nodes)) { |
|
70 | return null; |
||
71 | } |
||
72 | |||
73 | 195 | return end($this->nodes)->name; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | public function count(): int |
||
83 | |||
84 | 86 | private function getNodeNamespace(Node $node): ?Name |
|
98 | |||
99 | /** |
||
100 | * @inheritdoc |
||
101 | */ |
||
102 | public function getIterator(): iterable |
||
106 | } |
||
107 |