> */ public function getNodeTypes() : array { return [Expression::class]; } /** * @param Expression $node * @return Stmt[]|null */ public function refactor(Node $node) : ?array { if (!$node->expr instanceof FuncCall) { return null; } $funcCall = $node->expr; if (!$this->isName($funcCall, 'array_push')) { return null; } if ($funcCall->isFirstClassCallable()) { return null; } if ($this->hasArraySpread($funcCall)) { return null; } $args = $funcCall->getArgs(); if ($args === []) { return null; } $firstArg = \array_shift($args); if ($args === []) { return null; } $arrayDimFetch = new ArrayDimFetch($firstArg->value); $newStmts = []; foreach ($args as $key => $arg) { $assign = new Assign($arrayDimFetch, $arg->value); $assignExpression = new Expression($assign); $newStmts[] = $assignExpression; // keep comments of first line if ($key === 0) { $this->mirrorComments($assignExpression, $node); } } return $newStmts; } private function hasArraySpread(FuncCall $funcCall) : bool { foreach ($funcCall->getArgs() as $arg) { if ($arg->unpack) { return \true; } } return \false; } }