rector/rules/Renaming/NodeManipulator/SwitchManipulator.php
Tomas Votruba 9af6860899 Updated Rector to commit 3b64243cf0b87f328c68d32d67e51ae7b611bbeb
3b64243cf0 [CodingStyle] Fix change short php version on VersionCompareFuncCallToConstantRector (#209)
2021-06-12 13:58:46 +00:00

30 lines
816 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Renaming\NodeManipulator;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Break_;
final class SwitchManipulator
{
/**
* @param Stmt[] $stmts
* @return Stmt[]
*/
public function removeBreakNodes(array $stmts) : array
{
foreach ($stmts as $key => $node) {
if (!$node instanceof \PhpParser\Node\Stmt\Break_) {
continue;
}
if (!$node->num instanceof \PhpParser\Node\Scalar\LNumber || $node->num->value === 1) {
unset($stmts[$key]);
continue;
}
$node->num = $node->num->value === 2 ? null : new \PhpParser\Node\Scalar\LNumber($node->num->value - 1);
}
return $stmts;
}
}