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 */ /** @var Array_[] $arrays */
$arrays = $this->betterNodeFinder->findInstanceOf($class, Array_::class); $arrays = $this->betterNodeFinder->findInstanceOf($class, Array_::class);
$classMethodName = $this->nodeNameResolver->getName($classMethod);
foreach ($arrays as $array) { foreach ($arrays as $array) {
if ($this->isInArrayMap($class, $array)) { if ($this->isInArrayMap($class, $array)) {
return \true; return \true;
} }
$arrayCallable = $this->arrayCallableMethodMatcher->match($array, $scope); $arrayCallable = $this->arrayCallableMethodMatcher->match($array, $scope, $classMethodName);
if ($arrayCallable instanceof ArrayCallableDynamicMethod) { if ($arrayCallable instanceof ArrayCallableDynamicMethod) {
return \true; return \true;
} }

View File

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

View File

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