Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture;

final class DoWhileMaybeReturned4
{
public function run(int $i)
{
do {
if (rand(0, 1)) {
goto execute;
}

return 2;
} while (++$i < 1);
execute:
echo 'test';
}
}

?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture;

final class DoWhileMaybeReturned4
{
public function run(int $i)
{
do {
if (rand(0, 1)) {
goto execute;
}

return 2;
} while (++$i < 1);
execute:
echo 'test';
return null;
}
}

?>

This file was deleted.

12 changes: 0 additions & 12 deletions rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Goto_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeVisitor;
use PHPStan\Type\NullType;
use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractRector;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver;
Expand All @@ -39,7 +37,6 @@ public function __construct(
private readonly TypeFactory $typeFactory,
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly ReturnTypeInferer $returnTypeInferer,
private readonly BetterNodeFinder $betterNodeFinder,
) {
}

Expand Down Expand Up @@ -114,15 +111,6 @@ public function refactor(Node $node): ?Node
return null;
}

$hasGoto = (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped(
$node,
fn (Node $node): bool => $node instanceof Goto_
);

if ($hasGoto) {
return null;
}

$hasChanged = false;
$this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use (
&$hasChanged
Expand Down
3 changes: 2 additions & 1 deletion rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ private function isStopped(Stmt $stmt): bool
|| $stmt instanceof Exit_
|| ($stmt instanceof Return_ && $stmt->expr instanceof Expr)
|| $stmt instanceof Yield_
|| $stmt instanceof YieldFrom;
|| $stmt instanceof YieldFrom
|| $stmt instanceof Goto_;
}

private function isSwitchWithAlwaysReturnOrExit(Switch_ $switch): bool
Expand Down