|
11 | 11 | use PhpParser\NodeVisitorAbstract; |
12 | 12 | use PhpParser\Parser; |
13 | 13 | use PhpParser\ParserFactory; |
| 14 | +use PhpParser\PhpVersion; |
14 | 15 | use PhpParser\PrettyPrinter\Standard; |
15 | 16 | use PhpParser\PrettyPrinterAbstract; |
16 | 17 | use PhpParser\Node\Expr\ArrowFunction; |
@@ -78,7 +79,7 @@ private static function getFinder(): NodeFinder |
78 | 79 |
|
79 | 80 | private function createParser(): Parser |
80 | 81 | { |
81 | | - return (new ParserFactory)->create(ParserFactory::PREFER_PHP7); |
| 82 | + return (new ParserFactory)->createForVersion(PhpVersion::getHostVersion()); |
82 | 83 | } |
83 | 84 |
|
84 | 85 | private function getReflector(\Closure $closure): \ReflectionFunction |
@@ -126,7 +127,7 @@ public function enterNode(Node $node) |
126 | 127 | return parent::enterNode($node); |
127 | 128 | } |
128 | 129 |
|
129 | | - public function beforeTraverse(array $nodes) |
| 130 | + public function beforeTraverse(array $nodes):? array |
130 | 131 | { |
131 | 132 | $this->stack = []; |
132 | 133 | return parent::beforeTraverse($nodes); |
@@ -201,20 +202,20 @@ public function enterNode(Node $node) |
201 | 202 | } |
202 | 203 |
|
203 | 204 | foreach ($use->uses as $useUse) { |
204 | | - if (end($useUse->name->parts) == end($node->parts)) { |
205 | | - $parts = array_merge($parts, $useUse->name->parts); |
| 205 | + if ($useUse->name->getLast() == $node->getLast()) { |
| 206 | + $parts = array_merge($parts, $useUse->name->getParts()); |
206 | 207 | return new Name\FullyQualified($parts, $node->getAttributes()); |
207 | 208 | } |
208 | 209 | } |
209 | 210 | } |
210 | 211 |
|
211 | 212 | if ($node->getAttribute('parent') instanceof Node\Expr\ConstFetch) { |
212 | | - if (in_array(strtolower($node->parts[0]), ['null', 'false', 'true'])) { |
| 213 | + if (in_array(strtolower($node->getFirst()), ['null', 'false', 'true'])) { |
213 | 214 | return $node; |
214 | 215 | } |
215 | 216 | foreach (get_defined_constants() as $name => $v) { |
216 | 217 | if ($node->parts[0] == $name) { |
217 | | - return new Name\FullyQualified($node->parts[0], $node->getAttributes()); |
| 218 | + return new Name\FullyQualified($node->getFirst(), $node->getAttributes()); |
218 | 219 | } |
219 | 220 | } |
220 | 221 | } |
@@ -244,19 +245,19 @@ public function enterNode(Node $node) |
244 | 245 |
|
245 | 246 | if ($this->namespace) { |
246 | 247 | return new Name\FullyQualified( |
247 | | - [...$this->namespace->name->parts, ...$node->parts], |
| 248 | + [...$this->namespace->name->getParts(), ...$node->getParts()], |
248 | 249 | $node->getAttributes() |
249 | 250 | ); |
250 | 251 | } else { |
251 | | - return new Name\FullyQualified($node->parts, $node->getAttributes()); |
| 252 | + return new Name\FullyQualified($node->getParts(), $node->getAttributes()); |
252 | 253 | } |
253 | 254 | } |
254 | 255 |
|
255 | 256 | if ($node instanceof Node\Scalar\MagicConst\Class_) { |
256 | 257 | if (!$cls) $cls = ($this->clsNameFinder)($node); |
257 | 258 | if ($cls) { |
258 | 259 | $part = $cls->name->name; |
259 | | - return new Node\Expr\ClassConstFetch(new Name\FullyQualified([...$this->namespace->name->parts, $part]), 'class', |
| 260 | + return new Node\Expr\ClassConstFetch(new Name\FullyQualified([...$this->namespace->name->getParts(), $part]), 'class', |
260 | 261 | $node->getAttributes() |
261 | 262 | ); |
262 | 263 | } |
|
0 commit comments