Updated Rector to commit 1b4395caa0579c559e484b75b7fd9baadc307c0c

1b4395caa0 [DX] Allow Arg in value resolver, as often used and intuitive (#5512)
This commit is contained in:
Tomas Votruba 2024-01-28 10:00:13 +00:00
parent c155c9cbaa
commit 2521815c9a
2 changed files with 24 additions and 8 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '040b839e71ec558c83553bc1462924e96993f6f0'; public const PACKAGE_VERSION = '1b4395caa0579c559e484b75b7fd9baadc307c0c';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-01-28 15:48:41'; public const RELEASE_DATE = '2024-01-28 10:58:04';
/** /**
* @var int * @var int
*/ */

View File

@ -5,6 +5,7 @@ namespace Rector\PhpParser\Node\Value;
use PhpParser\ConstExprEvaluationException; use PhpParser\ConstExprEvaluationException;
use PhpParser\ConstExprEvaluator; use PhpParser\ConstExprEvaluator;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\ClassConstFetch;
@ -17,6 +18,7 @@ use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider; use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\ConstantScalarType; use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\ConstantType;
use PHPStan\Type\TypeWithClassName; use PHPStan\Type\TypeWithClassName;
use Rector\Enum\ObjectReference; use Rector\Enum\ObjectReference;
use Rector\Exception\ShouldNotHappenException; use Rector\Exception\ShouldNotHappenException;
@ -91,10 +93,14 @@ final class ValueResolver
return $this->getValue($expr) === $value; return $this->getValue($expr) === $value;
} }
/** /**
* @param \PhpParser\Node\Arg|\PhpParser\Node\Expr $expr
* @return mixed * @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) { if ($expr instanceof Concat) {
return $this->processConcat($expr, $resolvedClassReference); return $this->processConcat($expr, $resolvedClassReference);
} }
@ -118,11 +124,8 @@ final class ValueResolver
return $this->nodeNameResolver->getName($expr); return $this->nodeNameResolver->getName($expr);
} }
$nodeStaticType = $this->nodeTypeResolver->getType($expr); $nodeStaticType = $this->nodeTypeResolver->getType($expr);
if ($nodeStaticType instanceof ConstantArrayType) { if ($nodeStaticType instanceof ConstantType) {
return $this->extractConstantArrayTypeValue($nodeStaticType); return $this->resolveConstantType($nodeStaticType);
}
if ($nodeStaticType instanceof ConstantScalarType) {
return $nodeStaticType->getValue();
} }
return null; return null;
} }
@ -318,4 +321,17 @@ final class ValueResolver
} }
return $parentClassName; 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;
}
} }