Skip to content

Commit

Permalink
Faster SilentVoidResolver (#4923)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 6, 2023
1 parent c171814 commit 15e9249
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\TypeDeclaration\TypeInferer;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
Expand All @@ -21,6 +22,7 @@
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Reflection\ReflectionResolver;


final class SilentVoidResolver
{
public function __construct(
Expand All @@ -44,15 +46,14 @@ public function hasExclusiveVoid(ClassMethod | Closure | Function_ $functionLike
return false;
}

/** @var Return_[] $returns */
$returns = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($functionLike, Return_::class);
foreach ($returns as $return) {
if ($return->expr instanceof Expr) {
return false;
$return = $this->betterNodeFinder->findFirstInFunctionLikeScoped($functionLike, function(Node $node) {
if ($node instanceof Return_ && $node->expr instanceof Expr) {
return true;
}
}
return false;
});

return true;
return $return === null;
}

public function hasSilentVoid(FunctionLike $functionLike): bool
Expand Down

0 comments on commit 15e9249

Please sign in to comment.