Updated Rector to commit b292010edec6f45b5a48d1f001edce95e05162f3

b292010ede [Performance][TypeDeclaration] Avoid double loop on SilentVoidResolver use NeverFuncCallAnalyzer (#5809)
This commit is contained in:
Tomas Votruba 2024-04-08 09:44:15 +00:00
parent 53fb366ec6
commit 8fba5b95f7
3 changed files with 25 additions and 24 deletions

View File

@ -4,7 +4,6 @@ declare (strict_types=1);
namespace Rector\TypeDeclaration\NodeAnalyzer;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
@ -23,24 +22,26 @@ final class NeverFuncCallAnalyzer
$this->nodeTypeResolver = $nodeTypeResolver;
}
/**
* @param ClassMethod|Closure|Function_|Stmt[] $functionLike
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\Function_ $functionLike
*/
public function hasNeverFuncCall($functionLike) : bool
{
$hasNeverType = \false;
$stmts = $functionLike instanceof FunctionLike ? (array) $functionLike->stmts : $functionLike;
foreach ($stmts as $stmt) {
if ($stmt instanceof Expression) {
$stmt = $stmt->expr;
}
if ($stmt instanceof Stmt) {
continue;
}
$stmtType = $this->nodeTypeResolver->getNativeType($stmt);
if ($stmtType instanceof NeverType) {
$hasNeverType = \true;
foreach ((array) $functionLike->stmts as $stmt) {
if ($this->isWithNeverTypeExpr($stmt)) {
return \true;
}
}
return $hasNeverType;
return \false;
}
public function isWithNeverTypeExpr(Stmt $stmt) : bool
{
if ($stmt instanceof Expression) {
$stmt = $stmt->expr;
}
if ($stmt instanceof Stmt) {
return \false;
}
$stmtType = $this->nodeTypeResolver->getNativeType($stmt);
return $stmtType instanceof NeverType;
}
}

View File

@ -85,8 +85,8 @@ final class SilentVoidResolver
private function hasStmtsAlwaysReturnOrExit(array $stmts) : bool
{
foreach ($stmts as $stmt) {
if ($stmt instanceof Expression) {
$stmt = $stmt->expr;
if ($this->neverFuncCallAnalyzer->isWithNeverTypeExpr($stmt)) {
return \true;
}
if ($this->isStopped($stmt)) {
return \true;
@ -105,7 +105,7 @@ final class SilentVoidResolver
return \true;
}
}
return $this->neverFuncCallAnalyzer->hasNeverFuncCall($stmts);
return \false;
}
private function isDoWithAlwaysReturnOrExit(Do_ $do) : bool
{
@ -137,11 +137,11 @@ final class SilentVoidResolver
}
return $this->hasStmtsAlwaysReturnOrExit($stmt->else->stmts);
}
/**
* @param \PhpParser\Node\Stmt|\PhpParser\Node\Expr $stmt
*/
private function isStopped($stmt) : bool
private function isStopped(Stmt $stmt) : bool
{
if ($stmt instanceof Expression) {
$stmt = $stmt->expr;
}
return $stmt instanceof Throw_ || $stmt instanceof Exit_ || $stmt instanceof Return_ && $stmt->expr instanceof Expr || $stmt instanceof Yield_ || $stmt instanceof YieldFrom;
}
private function isSwitchWithAlwaysReturnOrExit(Switch_ $switch) : bool

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '9939ced45eb3479a1d8b2b9339512398118b92d9';
public const PACKAGE_VERSION = 'b292010edec6f45b5a48d1f001edce95e05162f3';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-04-08 16:17:37';
public const RELEASE_DATE = '2024-04-08 16:41:47';
/**
* @var int
*/