Skip to content

Commit

Permalink
Updated Rector to commit 63201f76725831988f1484476f6f84e0976a5742
Browse files Browse the repository at this point in the history
rectorphp/rector-src@63201f7 [CodeQuality] Skip Superglobals variable on SimplifyEmptyCheckOnEmptyArrayRector (#5369)
  • Loading branch information
TomasVotruba committed Dec 17, 2023
1 parent 291e258 commit 335a386
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 335a386

Please sign in to comment.