mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 13:13:31 +00:00
[EarlyReturn] Skip ChangeOrIfReturnToEarlyReturnRector on next node is null or return void (#796)
This commit is contained in:
parent
9247ba932a
commit
654d4a2a2b
|
@ -12,6 +12,7 @@ use PhpParser\Node\Stmt\If_;
|
|||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\NodeManipulator\IfManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -89,6 +90,15 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$nextNode = $node->getAttribute(AttributeKey::NEXT_NODE);
|
||||
if ($nextNode === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($nextNode instanceof Return_ && $nextNode->expr === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Return_ $return */
|
||||
$return = $node->stmts[0];
|
||||
$ifs = $this->createMultipleIfs($node->cond, $return, []);
|
||||
|
|
|
@ -31,12 +31,10 @@ class AndNextOrReturnVoid
|
|||
*/
|
||||
public function run($a, $b, $c, $d)
|
||||
{
|
||||
if ($a && $b) {
|
||||
return null;
|
||||
}
|
||||
if ($c) {
|
||||
if ($a && $b || $c) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,7 @@ class ComplexIfCondOrWithoutElseIf
|
|||
{
|
||||
public function run($a, $b, $c)
|
||||
{
|
||||
if ($a && false === $b) {
|
||||
return 'a';
|
||||
}
|
||||
if (! $c) {
|
||||
if (($a && false === $b) || ! $c) {
|
||||
return 'a';
|
||||
}
|
||||
return 'b';
|
||||
|
|
Loading…
Reference in New Issue
Block a user