Updated Rector to commit fc250dd8da281cb79f5657d2f5d6c6c0053e54d1

fc250dd8da [DeadCode] Fix array callable with constructor args (#5770)
This commit is contained in:
Tomas Votruba 2024-03-24 14:10:21 +00:00
parent 078e4b92d7
commit be393d497b
3 changed files with 12 additions and 8 deletions

View File

@ -134,11 +134,12 @@ final class IsClassMethodUsedAnalyzer
{
/** @var Array_[] $arrays */
$arrays = $this->betterNodeFinder->findInstanceOf($class, Array_::class);
$classMethodName = $this->nodeNameResolver->getName($classMethod);
foreach ($arrays as $array) {
if ($this->isInArrayMap($class, $array)) {
return \true;
}
$arrayCallable = $this->arrayCallableMethodMatcher->match($array, $scope);
$arrayCallable = $this->arrayCallableMethodMatcher->match($array, $scope, $classMethodName);
if ($arrayCallable instanceof ArrayCallableDynamicMethod) {
return \true;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '25f3af626f841f7e62606a3a9aa64789a460f74c';
public const PACKAGE_VERSION = 'fc250dd8da281cb79f5657d2f5d6c6c0053e54d1';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-03-24 00:27:33';
public const RELEASE_DATE = '2024-03-24 21:08:05';
/**
* @var int
*/

View File

@ -61,7 +61,7 @@ final class ArrayCallableMethodMatcher
* @see https://github.com/rectorphp/rector-src/pull/909
* @return null|\Rector\NodeCollector\ValueObject\ArrayCallableDynamicMethod|\Rector\NodeCollector\ValueObject\ArrayCallable
*/
public function match(Array_ $array, Scope $scope)
public function match(Array_ $array, Scope $scope, ?string $classMethodName = null)
{
if (\count($array->items) !== 2) {
return null;
@ -73,7 +73,7 @@ final class ArrayCallableMethodMatcher
$items = $array->items;
// $this, self, static, FQN
$firstItemValue = $items[0]->value;
$callerType = $this->resolveCallerType($firstItemValue, $scope);
$callerType = $this->resolveCallerType($firstItemValue, $scope, $classMethodName);
if (!$callerType instanceof TypeWithClassName) {
return null;
}
@ -137,7 +137,7 @@ final class ArrayCallableMethodMatcher
/**
* @return \PHPStan\Type\MixedType|\PHPStan\Type\ObjectType
*/
private function resolveClassConstFetchType(ClassConstFetch $classConstFetch, Scope $scope)
private function resolveClassConstFetchType(ClassConstFetch $classConstFetch, Scope $scope, ?string $classMethodName)
{
$classConstantReference = $this->valueResolver->getValue($classConstFetch);
if ($classConstantReference === ObjectReference::STATIC) {
@ -159,6 +159,9 @@ final class ArrayCallableMethodMatcher
if (!$hasConstruct) {
return new ObjectType($classConstantReference, null, $classReflection);
}
if (\is_string($classMethodName) && $classReflection->hasNativeMethod($classMethodName)) {
return new ObjectType($classConstantReference, null, $classReflection);
}
$extendedMethodReflection = $classReflection->getMethod(MethodName::CONSTRUCT, $scope);
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::selectSingle($extendedMethodReflection->getVariants());
foreach ($parametersAcceptorWithPhpDocs->getParameters() as $parameterReflectionWithPhpDoc) {
@ -168,11 +171,11 @@ final class ArrayCallableMethodMatcher
}
return new ObjectType($classConstantReference, null, $classReflection);
}
private function resolveCallerType(Expr $expr, Scope $scope) : Type
private function resolveCallerType(Expr $expr, Scope $scope, ?string $classMethodName) : Type
{
if ($expr instanceof ClassConstFetch) {
// static ::class reference?
$callerType = $this->resolveClassConstFetchType($expr, $scope);
$callerType = $this->resolveClassConstFetchType($expr, $scope, $classMethodName);
} else {
$callerType = $this->nodeTypeResolver->getType($expr);
}