Skip to content

Commit

Permalink
[CodeQuality] Handle Switch maybe return on ExplicitReturnNullRector (#…
Browse files Browse the repository at this point in the history
…5801)

* [CodeQuality] Handle Switch maybe return on ExplicitReturnNullRector

* Fix
  • Loading branch information
samsonasik authored Apr 3, 2024
1 parent 0348124 commit a43f371
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

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

class SwitchMaybeReturn
{
public function run(int $number)
{
switch ($number) {
case 1:
return 1;
case 2:
default:
}
}
}

?>
-----
<?php

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

class SwitchMaybeReturn
{
public function run(int $number)
{
switch ($number) {
case 1:
return 1;
case 2:
default:
}
return null;
}
}

?>
2 changes: 1 addition & 1 deletion rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function isSwitchWithAlwaysReturnOrExit(Switch_ $switch): bool

foreach ($switch->cases as $case) {
if (! $case->cond instanceof Expr) {
$hasDefault = true;
$hasDefault = $case->stmts !== [];
break;
}
}
Expand Down

0 comments on commit a43f371

Please sign in to comment.