Skip to content

Commit

Permalink
Updated Rector to commit 1b4395caa0579c559e484b75b7fd9baadc307c0c
Browse files Browse the repository at this point in the history
rectorphp/rector-src@1b4395c [DX] Allow Arg in value resolver, as often used and intuitive (#5512)
  • Loading branch information
TomasVotruba committed Jan 28, 2024
1 parent c155c9c commit 2521815
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
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 = '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
*/
Expand Down
28 changes: 22 additions & 6 deletions src/PhpParser/Node/Value/ValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 2521815

Please sign in to comment.