From 970b70122703ebe1fb87320ba9da1b1ed213e795 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 10 Oct 2023 10:46:27 +0000 Subject: [PATCH] Updated Rector to commit 6cb63f3752012f33f691844906e56d1045c8bfcf https://github.com/rectorphp/rector-src/commit/6cb63f3752012f33f691844906e56d1045c8bfcf [DeadCode] Skip indirect variable definition on RemoveNonExistingVarAnnotationRector (#5152) --- .../Node/RemoveNonExistingVarAnnotationRector.php | 13 +++++++++---- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php b/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php index f4f2d8d9cd4..0ebc960db2b 100644 --- a/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php +++ b/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php @@ -4,6 +4,7 @@ declare (strict_types=1); namespace Rector\DeadCode\Rector\Node; use PhpParser\Node; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\New_; @@ -13,6 +14,7 @@ use PhpParser\Node\Stmt\Echo_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\If_; +use PhpParser\Node\Stmt\InlineHTML; use PhpParser\Node\Stmt\Nop; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Static_; @@ -136,7 +138,7 @@ CODE_SAMPLE continue; } $variableName = \ltrim($varTagValueNode->variableName, '$'); - if ($variableName === '' && $this->isAnnotatableReturn($stmt)) { + if ($variableName === '' && $this->isAllowedEmptyVariableName($stmt)) { continue; } if ($this->hasVariableName($stmt, $variableName)) { @@ -172,7 +174,7 @@ CODE_SAMPLE return \true; } } - return \false; + return isset($stmtsAware->stmts[$key + 1]) && $stmtsAware->stmts[$key + 1] instanceof InlineHTML; } private function hasVariableName(Stmt $stmt, string $variableName) : bool { @@ -200,8 +202,11 @@ CODE_SAMPLE } return \strpos($varTagValueNode->description, '}') !== \false; } - private function isAnnotatableReturn(Stmt $stmt) : bool + private function isAllowedEmptyVariableName(Stmt $stmt) : bool { - return $stmt instanceof Return_ && $stmt->expr instanceof CallLike && !$stmt->expr instanceof New_; + if ($stmt instanceof Return_ && $stmt->expr instanceof CallLike && !$stmt->expr instanceof New_) { + return \true; + } + return $stmt instanceof Expression && $stmt->expr instanceof Assign && $stmt->expr->var instanceof Variable; } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 1420b65686d..2d261d8dc06 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'ee7e92ca7b3507a2903a21bb52b9f840ae3cc2e8'; + public const PACKAGE_VERSION = '6cb63f3752012f33f691844906e56d1045c8bfcf'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-10-10 15:29:10'; + public const RELEASE_DATE = '2023-10-10 17:42:30'; /** * @var int */