From 2521815c9af7f93c82eb7d166c94021fc98f457d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 28 Jan 2024 10:00:13 +0000 Subject: [PATCH] Updated Rector to commit 1b4395caa0579c559e484b75b7fd9baadc307c0c https://github.com/rectorphp/rector-src/commit/1b4395caa0579c559e484b75b7fd9baadc307c0c [DX] Allow Arg in value resolver, as often used and intuitive (#5512) --- src/Application/VersionResolver.php | 4 ++-- src/PhpParser/Node/Value/ValueResolver.php | 28 +++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 1cfb5a462251..3228f7bb693a 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 = '040b839e71ec558c83553bc1462924e96993f6f0'; + public const PACKAGE_VERSION = '1b4395caa0579c559e484b75b7fd9baadc307c0c'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-01-28 15:48:41'; + public const RELEASE_DATE = '2024-01-28 10:58:04'; /** * @var int */ diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index a8e9077a84f3..44d63ac63920 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -5,6 +5,7 @@ use PhpParser\ConstExprEvaluationException; use PhpParser\ConstExprEvaluator; +use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\ClassConstFetch; @@ -17,6 +18,7 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\ConstantScalarType; +use PHPStan\Type\ConstantType; use PHPStan\Type\TypeWithClassName; use Rector\Enum\ObjectReference; use Rector\Exception\ShouldNotHappenException; @@ -91,10 +93,14 @@ public function isValue(Expr $expr, $value) : bool return $this->getValue($expr) === $value; } /** + * @param \PhpParser\Node\Arg|\PhpParser\Node\Expr $expr * @return mixed */ - public function getValue(Expr $expr, bool $resolvedClassReference = \false) + public function getValue($expr, bool $resolvedClassReference = \false) { + if ($expr instanceof Arg) { + $expr = $expr->value; + } if ($expr instanceof Concat) { return $this->processConcat($expr, $resolvedClassReference); } @@ -118,11 +124,8 @@ public function getValue(Expr $expr, bool $resolvedClassReference = \false) return $this->nodeNameResolver->getName($expr); } $nodeStaticType = $this->nodeTypeResolver->getType($expr); - if ($nodeStaticType instanceof ConstantArrayType) { - return $this->extractConstantArrayTypeValue($nodeStaticType); - } - if ($nodeStaticType instanceof ConstantScalarType) { - return $nodeStaticType->getValue(); + if ($nodeStaticType instanceof ConstantType) { + return $this->resolveConstantType($nodeStaticType); } return null; } @@ -318,4 +321,17 @@ private function resolveClassFromSelfStaticParent(ClassConstFetch $classConstFet } return $parentClassName; } + /** + * @return mixed + */ + private function resolveConstantType(ConstantType $constantType) + { + if ($constantType instanceof ConstantArrayType) { + return $this->extractConstantArrayTypeValue($constantType); + } + if ($constantType instanceof ConstantScalarType) { + return $constantType->getValue(); + } + return null; + } }