mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
Merge branch 'breaking_runnable_test_for__ChangeNestedForeachIfsToEarlyContinueRector'
This commit is contained in:
commit
9796048c8c
@ -139,11 +139,15 @@ PHP
|
||||
|
||||
// special case
|
||||
if ($invertedCondition instanceof BooleanNot && $invertedCondition->expr instanceof BooleanAnd) {
|
||||
$booleanNotPartIf = new If_(new BooleanNot($invertedCondition->expr->left));
|
||||
$foreach->stmts[] = $booleanNotPartIf;
|
||||
$leftExpr = $this->negateOrDeNegate($invertedCondition->expr->left);
|
||||
$if = new If_($leftExpr);
|
||||
$if->stmts[] = new Continue_();
|
||||
$foreach->stmts[] = $if;
|
||||
|
||||
$booleanNotPartIf = new If_(new BooleanNot($invertedCondition->expr->right));
|
||||
$foreach->stmts[] = $booleanNotPartIf;
|
||||
$rightExpr = $this->negateOrDeNegate($invertedCondition->expr->right);
|
||||
$if = new If_($rightExpr);
|
||||
$if->stmts[] = new Continue_();
|
||||
$foreach->stmts[] = $if;
|
||||
|
||||
return;
|
||||
}
|
||||
@ -155,4 +159,13 @@ PHP
|
||||
|
||||
$foreach->stmts[] = $nestedIfWithOnlyReturn;
|
||||
}
|
||||
|
||||
private function negateOrDeNegate(Node\Expr $expr): Node\Expr
|
||||
{
|
||||
if ($expr instanceof BooleanNot) {
|
||||
return $expr->expr;
|
||||
}
|
||||
|
||||
return new BooleanNot($expr);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector\Fixture;
|
||||
|
||||
use Rector\Core\Testing\Contract\RunnableInterface;
|
||||
|
||||
class MultiExprsWithBoolOprnds implements RunnableInterface
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$partPackageList = [ new \StdClass(), 'string' ];
|
||||
$payload = [];
|
||||
|
||||
foreach ($partPackageList as $partPackage) {
|
||||
if (! is_null($partPackage) && ! is_object($partPackage)) {
|
||||
if (1 == '1' || 2 == 't') {
|
||||
$payload[] = $partPackage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($payload);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector\Fixture;
|
||||
|
||||
use Rector\Core\Testing\Contract\RunnableInterface;
|
||||
|
||||
class MultiExprsWithBoolOprnds implements RunnableInterface
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$partPackageList = [ new \StdClass(), 'string' ];
|
||||
$payload = [];
|
||||
|
||||
foreach ($partPackageList as $partPackage) {
|
||||
if (is_null($partPackage)) {
|
||||
continue;
|
||||
}
|
||||
if (is_object($partPackage)) {
|
||||
continue;
|
||||
}
|
||||
if (1 == '1' && 2 == 't') {
|
||||
continue;
|
||||
}
|
||||
$payload[] = $partPackage;
|
||||
}
|
||||
|
||||
return json_encode($payload);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user