Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelmaksimov25 committed Nov 6, 2023
2 parents c18ff82 + 431e07e commit c1e9e36
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Builder/Visitor/AddPluginToPluginListVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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_(),
),
);
}
Expand Down

0 comments on commit c1e9e36

Please sign in to comment.