Skip to content

Commit

Permalink
[TypeDeclaration] Skip maybe not returned on while on ReturnUnionType…
Browse files Browse the repository at this point in the history
…Rector (#5812)
  • Loading branch information
samsonasik committed Apr 8, 2024
1 parent 54e2e11 commit 1bbb3fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector\Fixture;

final class SkipWhileMaybeNeverReturned
{
public function run(int $i)
{
while (++$i < 1) {
if (rand(0,1)) {
return 1;
}

return '1';
}
}
}
2 changes: 1 addition & 1 deletion rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function isDoOrWhileWithAlwaysReturnOrExit(Stmt $stmt): bool
return false;
}

return ! $this->isFoundLoopControl($stmt);;
return $stmt instanceof Do_ && ! $this->isFoundLoopControl($stmt);;
}

private function isIfReturn(Stmt|Expr $stmt): bool
Expand Down

0 comments on commit 1bbb3fa

Please sign in to comment.