Updated Rector to commit aa71d0e5f699df743279045c6f9cd4e7d08b7805

aa71d0e5f6 [DeadCode] Allow pass stmts instead of $node on StmtsManipulator::isVariableUsedInNextStmt() (#5968)
This commit is contained in:
Tomas Votruba 2024-06-14 10:35:06 +00:00
parent 9d34f08b91
commit 6a6d8b94d2
4 changed files with 16 additions and 19 deletions

View File

@ -108,7 +108,7 @@ CODE_SAMPLE
$assignedVariableNamesByStmtPosition = $this->resolvedAssignedVariablesByStmtPosition($stmts);
$hasChanged = \false;
foreach ($assignedVariableNamesByStmtPosition as $stmtPosition => $variableName) {
if ($this->isVariableUsedInFollowingStmts($node, $stmtPosition, $variableName)) {
if ($this->isVariableUsedInFollowingStmts($stmts, $stmtPosition, $variableName)) {
continue;
}
/** @var Expression<Assign> $currentStmt */
@ -145,14 +145,11 @@ CODE_SAMPLE
});
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
* @param Stmt[] $stmts
*/
private function isVariableUsedInFollowingStmts($functionLike, int $assignStmtPosition, string $variableName) : bool
private function isVariableUsedInFollowingStmts(array $stmts, int $assignStmtPosition, string $variableName) : bool
{
if ($functionLike->stmts === null) {
return \false;
}
foreach ($functionLike->stmts as $key => $stmt) {
foreach ($stmts as $key => $stmt) {
// do not look yet
if ($key <= $assignStmtPosition) {
continue;
@ -161,11 +158,7 @@ CODE_SAMPLE
if (!$stmtScope instanceof Scope) {
continue;
}
$foundVariable = $this->betterNodeFinder->findVariableOfName($stmt, $variableName);
if ($foundVariable instanceof Variable) {
return \true;
}
if ($this->stmtsManipulator->isVariableUsedInNextStmt($functionLike, $key, $variableName)) {
if ($this->stmtsManipulator->isVariableUsedInNextStmt($stmts, $key, $variableName)) {
return \true;
}
}

View File

@ -136,10 +136,11 @@ CODE_SAMPLE
*/
private function processForForeach($for, int $key, StmtsAwareInterface $stmtsAware) : void
{
$stmts = (array) $stmtsAware->stmts;
if ($for instanceof For_) {
$variables = $this->betterNodeFinder->findInstanceOf(\array_merge($for->init, $for->cond, $for->loop), Variable::class);
foreach ($variables as $variable) {
if ($this->stmtsManipulator->isVariableUsedInNextStmt($stmtsAware, $key + 1, (string) $this->getName($variable))) {
if ($this->stmtsManipulator->isVariableUsedInNextStmt($stmts, $key + 1, (string) $this->getName($variable))) {
return;
}
}
@ -150,7 +151,7 @@ CODE_SAMPLE
$exprs = \array_filter([$for->expr, $for->valueVar, $for->valueVar]);
$variables = $this->betterNodeFinder->findInstanceOf($exprs, Variable::class);
foreach ($variables as $variable) {
if ($this->stmtsManipulator->isVariableUsedInNextStmt($stmtsAware, $key + 1, (string) $this->getName($variable))) {
if ($this->stmtsManipulator->isVariableUsedInNextStmt($stmts, $key + 1, (string) $this->getName($variable))) {
return;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'dfb55d1c65e483a0d826a4d583a37232cdd1854b';
public const PACKAGE_VERSION = 'aa71d0e5f699df743279045c6f9cd4e7d08b7805';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-06-14 10:03:16';
public const RELEASE_DATE = '2024-06-14 17:31:49';
/**
* @var int
*/

View File

@ -73,12 +73,15 @@ final class StmtsManipulator
});
return $stmts;
}
public function isVariableUsedInNextStmt(StmtsAwareInterface $stmtsAware, int $jumpToKey, string $variableName) : bool
/**
* @param StmtsAwareInterface|Stmt[] $stmtsAware
*/
public function isVariableUsedInNextStmt($stmtsAware, int $jumpToKey, string $variableName) : bool
{
if ($stmtsAware->stmts === null) {
if ($stmtsAware instanceof StmtsAwareInterface && $stmtsAware->stmts === null) {
return \false;
}
$stmts = \array_slice($stmtsAware->stmts, $jumpToKey, null, \true);
$stmts = \array_slice($stmtsAware instanceof StmtsAwareInterface ? $stmtsAware->stmts : $stmtsAware, $jumpToKey, null, \true);
if ((bool) $this->betterNodeFinder->findVariableOfName($stmts, $variableName)) {
return \true;
}