protected function checkAddingToArrayInByReferenceForeach(Node $node)
{
if (!($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignRef) || !$node->var instanceof Node\Expr\ArrayDimFetch || !$node->var->var instanceof Node\Expr\Variable) {
return;
}
/** @var Node\Stmt\Foreach_ $foreach */
foreach ($this->getCurrentLoopStack() as $foreach) {
if (!$foreach->byRef) {
continue;
}
if ($node->var->var->name === $this->getForeachVariableName($foreach)) {
$this->addContextMessage('Possible adding to array on the last iteration of a by-reference foreach loop', $node);
}
}
}