rector/rules/Php80/NodeFactory/MatchArmsFactory.php
Tomas Votruba 444b9f0d13 Updated Rector to commit 1d2b3248d24fa37e04fc9252f304df3ab6ae4a88
1d2b3248d2 [PHP 8.0] Add implicit return after switch support (#181)
2021-06-08 11:02:16 +00:00

30 lines
828 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Php80\NodeFactory;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\MatchArm;
use Rector\Php80\ValueObject\CondAndExpr;
final class MatchArmsFactory
{
/**
* @param CondAndExpr[] $condAndExprs
* @return MatchArm[]
*/
public function createFromCondAndExprs(array $condAndExprs) : array
{
$matchArms = [];
foreach ($condAndExprs as $condAndExpr) {
$expr = $condAndExpr->getExpr();
if ($expr instanceof \PhpParser\Node\Expr\Assign) {
// $this->assignExpr = $expr->var;
$expr = $expr->expr;
}
$condExprs = $condAndExpr->getCondExprs();
$matchArms[] = new \PhpParser\Node\MatchArm($condExprs, $expr);
}
return $matchArms;
}
}