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; namespace Rector\TypeDeclaration\NodeAnalyzer;
use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Expression;
@ -23,24 +22,26 @@ final class NeverFuncCallAnalyzer
$this->nodeTypeResolver = $nodeTypeResolver; $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 public function hasNeverFuncCall($functionLike) : bool
{ {
$hasNeverType = \false; foreach ((array) $functionLike->stmts as $stmt) {
$stmts = $functionLike instanceof FunctionLike ? (array) $functionLike->stmts : $functionLike; if ($this->isWithNeverTypeExpr($stmt)) {
foreach ($stmts as $stmt) { return \true;
if ($stmt instanceof Expression) {
$stmt = $stmt->expr;
}
if ($stmt instanceof Stmt) {
continue;
}
$stmtType = $this->nodeTypeResolver->getNativeType($stmt);
if ($stmtType instanceof NeverType) {
$hasNeverType = \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 private function hasStmtsAlwaysReturnOrExit(array $stmts) : bool
{ {
foreach ($stmts as $stmt) { foreach ($stmts as $stmt) {
if ($stmt instanceof Expression) { if ($this->neverFuncCallAnalyzer->isWithNeverTypeExpr($stmt)) {
$stmt = $stmt->expr; return \true;
} }
if ($this->isStopped($stmt)) { if ($this->isStopped($stmt)) {
return \true; return \true;
@ -105,7 +105,7 @@ final class SilentVoidResolver
return \true; return \true;
} }
} }
return $this->neverFuncCallAnalyzer->hasNeverFuncCall($stmts); return \false;
} }
private function isDoWithAlwaysReturnOrExit(Do_ $do) : bool private function isDoWithAlwaysReturnOrExit(Do_ $do) : bool
{ {
@ -137,11 +137,11 @@ final class SilentVoidResolver
} }
return $this->hasStmtsAlwaysReturnOrExit($stmt->else->stmts); return $this->hasStmtsAlwaysReturnOrExit($stmt->else->stmts);
} }
/** private function isStopped(Stmt $stmt) : bool
* @param \PhpParser\Node\Stmt|\PhpParser\Node\Expr $stmt
*/
private function isStopped($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; 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 private function isSwitchWithAlwaysReturnOrExit(Switch_ $switch) : bool

View File

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