|
22 | 22 | use PhpParser\Node\Expr\BinaryOp\NotIdentical; |
23 | 23 | use PhpParser\Node\Expr\Cast; |
24 | 24 | use PhpParser\Node\Expr\ClassConstFetch; |
| 25 | +use PhpParser\Node\Expr\Clone_; |
25 | 26 | use PhpParser\Node\Expr\ConstFetch; |
26 | 27 | use PhpParser\Node\Expr\FuncCall; |
| 28 | +use PhpParser\Node\Expr\Instanceof_; |
27 | 29 | use PhpParser\Node\Expr\MethodCall; |
28 | 30 | use PhpParser\Node\Expr\New_; |
| 31 | +use PhpParser\Node\Expr\NullsafeMethodCall; |
| 32 | +use PhpParser\Node\Expr\NullsafePropertyFetch; |
29 | 33 | use PhpParser\Node\Expr\PropertyFetch; |
30 | 34 | use PhpParser\Node\Expr\StaticCall; |
31 | 35 | use PhpParser\Node\Expr\StaticPropertyFetch; |
|
43 | 47 | use PHPStan\Type\Type; |
44 | 48 | use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; |
45 | 49 | use Rector\Enum\ObjectReference; |
46 | | -use Rector\Exception\NotImplementedYetException; |
47 | 50 | use Rector\Exception\ShouldNotHappenException; |
48 | 51 | use Rector\NodeDecorator\PropertyTypeDecorator; |
49 | 52 | use Rector\NodeTypeResolver\Node\AttributeKey; |
@@ -346,7 +349,7 @@ public function createReprintedNode(Node $node): Node |
346 | 349 | private function createArrayItem($item, $key = null): ArrayItem |
347 | 350 | { |
348 | 351 | $arrayItem = null; |
349 | | - if ($item instanceof Variable || $item instanceof MethodCall || $item instanceof StaticCall || $item instanceof FuncCall || $item instanceof Concat || $item instanceof Scalar || $item instanceof Cast || $item instanceof ConstFetch) { |
| 352 | + if ($item instanceof Variable || $item instanceof MethodCall || $item instanceof StaticCall || $item instanceof FuncCall || $item instanceof Concat || $item instanceof Scalar || $item instanceof Cast || $item instanceof ConstFetch || $item instanceof PropertyFetch || $item instanceof StaticPropertyFetch || $item instanceof NullsafePropertyFetch || $item instanceof NullsafeMethodCall || $item instanceof Clone_ || $item instanceof Instanceof_) { |
350 | 353 | $arrayItem = new ArrayItem($item); |
351 | 354 | } elseif ($item instanceof Identifier) { |
352 | 355 | $string = new String_($item->toString()); |
@@ -376,8 +379,16 @@ private function createArrayItem($item, $key = null): ArrayItem |
376 | 379 | $this->decorateArrayItemWithKey($key, $arrayItem); |
377 | 380 | return $arrayItem; |
378 | 381 | } |
379 | | - $nodeClass = is_object($item) ? get_class($item) : $item; |
380 | | - throw new NotImplementedYetException(sprintf('Not implemented yet. Go to "%s()" and add check for "%s" node.', __METHOD__, (string) $nodeClass)); |
| 382 | + // fallback to other nodes |
| 383 | + if ($item instanceof Expr) { |
| 384 | + $arrayItem = new ArrayItem($item); |
| 385 | + $this->decorateArrayItemWithKey($key, $arrayItem); |
| 386 | + return $arrayItem; |
| 387 | + } |
| 388 | + $itemValue = BuilderHelpers::normalizeValue($item); |
| 389 | + $arrayItem = new ArrayItem($itemValue); |
| 390 | + $this->decorateArrayItemWithKey($key, $arrayItem); |
| 391 | + return $arrayItem; |
381 | 392 | } |
382 | 393 | /** |
383 | 394 | * @param int|string|null $key |
|
0 commit comments