diff --git a/src/Builder/Visitor/AddPluginToPluginListVisitor.php b/src/Builder/Visitor/AddPluginToPluginListVisitor.php index 84c48370..38bad1dd 100644 --- a/src/Builder/Visitor/AddPluginToPluginListVisitor.php +++ b/src/Builder/Visitor/AddPluginToPluginListVisitor.php @@ -211,7 +211,10 @@ protected function addNewPluginWithConditionIntoList(ClassMethod $node): Node $newStmts[] = $this->createNewConditionStatement($returnStmt->expr); } if ($returnStmt->expr instanceof FuncCall || $returnStmt->expr instanceof Array_) { - $newStmts[] = $this->createAssignEmptyArray(static::PLUGINS_VARIBLE); + $newStmts[] = $this->createAssignArray( + static::PLUGINS_VARIBLE, + $returnStmt->expr instanceof Array_ ? $returnStmt->expr : null, + ); $newStmts[] = $this->createNewConditionStatement((new BuilderFactory())->var(static::PLUGINS_VARIBLE)); $returnStmt->expr = (new BuilderFactory())->var(static::PLUGINS_VARIBLE); } @@ -223,15 +226,16 @@ protected function addNewPluginWithConditionIntoList(ClassMethod $node): Node /** * @param string $varName + * @param \PhpParser\Node\Expr\Array_|null $initialArray * * @return \PhpParser\Node\Stmt\Expression */ - protected function createAssignEmptyArray(string $varName): Expression + protected function createAssignArray(string $varName, ?Array_ $initialArray = null): Expression { return new Expression( new Assign( (new BuilderFactory())->var($varName), - new Array_(), + $initialArray ?? new Array_(), ), ); }