Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeQuality] Add Goto_ possible return null on SilentVoidResolver under Do_ #5773

Merged
merged 1 commit into from
Mar 25, 2024
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;
}
}

?>
3 changes: 2 additions & 1 deletion rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Goto_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Switch_;
Expand Down Expand Up @@ -112,7 +113,7 @@ private function isDoWithAlwaysReturnOrExit(Do_ $do): bool

return ! (bool) $this->betterNodeFinder->findFirst(
$do->stmts,
static fn (Node $node): bool => $node instanceof Break_ || $node instanceof Continue_
static fn (Node $node): bool => $node instanceof Break_ || $node instanceof Continue_ || $node instanceof Goto_
);
}

Expand Down
Loading