1 | <?php |
||
29 | final class ScopeUseStmtNodeVisitor extends NodeVisitorAbstract |
||
30 | { |
||
31 | private $prefix; |
||
32 | private $whitelist; |
||
33 | private $whitelistedStatements; |
||
34 | |||
35 | /** |
||
36 | * @param string $prefix |
||
37 | * @param string[] $whitelist |
||
38 | * @param WhitelistedStatements $whitelistedStatements |
||
39 | */ |
||
40 | public function __construct(string $prefix, array $whitelist, WhitelistedStatements $whitelistedStatements) |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | public function enterNode(Node $node) |
||
85 | |||
86 | /** |
||
87 | * Removes use statements of whitelisted classes. |
||
88 | * |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function leaveNode(Node $node) |
||
107 | |||
108 | // /** |
||
|
|||
109 | // * @var string |
||
110 | // */ |
||
111 | // private $prefix; |
||
112 | // |
||
113 | // /** |
||
114 | // * @var array |
||
115 | // */ |
||
116 | // private $aliases; |
||
117 | // |
||
118 | // public function __construct(string $prefix) |
||
119 | // { |
||
120 | // $this->prefix = $prefix; |
||
121 | // } |
||
122 | // |
||
123 | // /** |
||
124 | // * @inheritdoc |
||
125 | // */ |
||
126 | // public function beforeTraverse(array $nodes) |
||
127 | // { |
||
128 | // $this->aliases = []; |
||
129 | // } |
||
130 | // |
||
131 | // /** |
||
132 | // * @inheritdoc |
||
133 | // */ |
||
134 | // public function enterNode(Node $node) |
||
135 | // { |
||
136 | // /* Collate all single level aliases */ |
||
137 | // if ($node instanceof UseUse |
||
138 | // && (!$node->hasAttribute('parent') |
||
139 | // || false === ($node->getAttribute('parent') instanceof GroupUse)) |
||
140 | // && $this->prefix !== $node->name->getFirst() |
||
141 | // && 1 === count($node->name->parts) |
||
142 | // && $node->alias !== $node->name->getFirst() |
||
143 | // ) { |
||
144 | // $this->aliases[$node->alias] = $node; |
||
145 | // |
||
146 | // return; |
||
147 | // } |
||
148 | // |
||
149 | // $this->scopeUseStmtIfUsedInAnyNameAsAliasedNamespace($node); |
||
150 | // } |
||
151 | // |
||
152 | // /** |
||
153 | // * @param Node $node |
||
154 | // */ |
||
155 | // private function scopeUseStmtIfUsedInAnyNameAsAliasedNamespace(Node $node) |
||
156 | // { |
||
157 | // if ($node instanceof Name |
||
158 | // && 1 < count($node->parts) |
||
159 | // && in_array($node->getFirst(), array_keys($this->aliases)) |
||
160 | // ) { |
||
161 | // $nodeToPrefix = $this->aliases[$node->getFirst()]; |
||
162 | // $nodeToPrefix->name = Name::concat($this->prefix, $nodeToPrefix->name); |
||
163 | // unset($this->aliases[$node->getFirst()]); |
||
164 | // } |
||
165 | // } |
||
166 | } |
||
167 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.