From 335a3861f813ac486295d6d3e3eee949715d4d55 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 17 Dec 2023 09:24:20 +0000 Subject: [PATCH] Updated Rector to commit 63201f76725831988f1484476f6f84e0976a5742 https://github.com/rectorphp/rector-src/commit/63201f76725831988f1484476f6f84e0976a5742 [CodeQuality] Skip Superglobals variable on SimplifyEmptyCheckOnEmptyArrayRector (#5369) --- .../SimplifyEmptyCheckOnEmptyArrayRector.php | 18 ++++++++++++++++-- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php b/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php index 8ba3c8402224..5c15a09b3335 100644 --- a/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php +++ b/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php @@ -20,6 +20,7 @@ use PHPStan\Type\ArrayType; use PHPStan\Type\MixedType; use Rector\Core\NodeAnalyzer\ExprAnalyzer; +use Rector\Core\Php\ReservedKeywordAnalyzer; use Rector\Core\PhpParser\AstResolver; use Rector\Core\Rector\AbstractScopeAwareRector; use Rector\Core\Reflection\ReflectionResolver; @@ -51,12 +52,18 @@ final class SimplifyEmptyCheckOnEmptyArrayRector extends AbstractScopeAwareRecto * @var \Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\AllAssignNodePropertyTypeInferer */ private $allAssignNodePropertyTypeInferer; - public function __construct(ExprAnalyzer $exprAnalyzer, ReflectionResolver $reflectionResolver, AstResolver $astResolver, AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer) + /** + * @readonly + * @var \Rector\Core\Php\ReservedKeywordAnalyzer + */ + private $reservedKeywordAnalyzer; + public function __construct(ExprAnalyzer $exprAnalyzer, ReflectionResolver $reflectionResolver, AstResolver $astResolver, AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer, ReservedKeywordAnalyzer $reservedKeywordAnalyzer) { $this->exprAnalyzer = $exprAnalyzer; $this->reflectionResolver = $reflectionResolver; $this->astResolver = $astResolver; $this->allAssignNodePropertyTypeInferer = $allAssignNodePropertyTypeInferer; + $this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer; } public function getRuleDefinition() : RuleDefinition { @@ -97,13 +104,20 @@ public function refactorWithScope(Node $node, Scope $scope) : ?Node } return new Identical($node->expr, new Array_()); } + private function isAllowedVariable(Variable $variable) : bool + { + if (\is_string($variable->name) && $this->reservedKeywordAnalyzer->isNativeVariable($variable->name)) { + return \false; + } + return !$this->exprAnalyzer->isNonTypedFromParam($variable); + } private function isAllowedExpr(Expr $expr, Scope $scope) : bool { if (!$scope->getType($expr) instanceof ArrayType) { return \false; } if ($expr instanceof Variable) { - return !$this->exprAnalyzer->isNonTypedFromParam($expr); + return $this->isAllowedVariable($expr); } if (!$expr instanceof PropertyFetch && !$expr instanceof StaticPropertyFetch) { return \false; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 31d2bd127dde..480c4508f036 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 = '54491a53f081fd8785269513b1650a524a9077f1'; + public const PACKAGE_VERSION = '63201f76725831988f1484476f6f84e0976a5742'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-12-17 07:27:47'; + public const RELEASE_DATE = '2023-12-17 16:22:12'; /** * @var int */