for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\Php7to5\NodeVisitors;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
/**
* Class ArrayListingReplacer
* @package Spatie\Php7to5\NodeVisitors
* @author Jiri Vrba <[email protected]>
*
* Replaces [$a, $b, $c] = ['a', 'b', 'c'] with list()
*/
class ArrayListingReplacer extends NodeVisitorAbstract
{
* {@inheritdoc}
public function leaveNode(Node $node)
if (!$node instanceof Node\Expr\Array_)
return;
$stack = [];
foreach ($node->items as $arrayItem)
if ($arrayItem->value instanceof Node\Expr\Variable)
$stack[] = $arrayItem->value;
}
if (!empty($stack))
return new Node\Expr\List_($stack);