Skip to content

Commit

Permalink
Remove CI status for rector/phpstan-rules on Readme (#5456) (#5458)
Browse files Browse the repository at this point in the history
Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
  • Loading branch information
mcsky and samsonasik committed Jan 11, 2024
1 parent 061ddc3 commit f24b01a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Switch_\SingularSwitchToIfRector\Fixture;

final class DefaultOnly
{
public function run($value)
{
$result = 1;
switch ($value) {
default:
$result = 1000;
break;
}

return $result;
}
}

?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\Switch_\SingularSwitchToIfRector\Fixture;

final class DefaultOnly
{
public function run($value)
{
$result = 1;
$result = 1000;

return $result;
}
}

?>
8 changes: 6 additions & 2 deletions rules/CodeQuality/Rector/Switch_/SingularSwitchToIfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Switch_;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -85,9 +87,11 @@ public function refactor(Node $node): array|If_|null

// only default → basically unwrap
if (! $onlyCase->cond instanceof Expr) {
return $onlyCase->stmts;
// remove default clause because it cause syntax error
return array_filter($onlyCase->stmts, function (Stmt $statement) {
return ! $statement instanceof Break_;
});
}

$if = new If_(new Identical($node->cond, $onlyCase->cond));
$if->stmts = $this->switchManipulator->removeBreakNodes($onlyCase->stmts);

Expand Down

0 comments on commit f24b01a

Please sign in to comment.