diff --git a/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/static_call.php.inc b/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/static_call.php.inc new file mode 100644 index 00000000000..07d27d8375c --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/static_call.php.inc @@ -0,0 +1,43 @@ + $second; + } +} + +?> +----- + $second; + } +} + +?> diff --git a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php index e407aa4b5ef..5ffb127cabc 100644 --- a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php +++ b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php @@ -38,6 +38,8 @@ use Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind; use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser; +use PhpParser\Node\Expr\ClassConstFetch; +use PhpParser\Node\Expr\StaticCall; final class AnonymousFunctionFactory { @@ -93,7 +95,15 @@ public function createFromPhpMethodReflection(PhpMethodReflection $phpMethodRefl $anonymousFunction->params = $newParams; - $innerMethodCall = new MethodCall($expr, $phpMethodReflection->getName()); + if ($expr instanceof ClassConstFetch && $expr->name instanceof Identifier && $this->nodeNameResolver->isName($expr->name, 'class')) { + /** @var Expr $expr */ + $expr = $expr->class; + } + + $innerMethodCall = $phpMethodReflection->isStatic() + ? new StaticCall($expr, $phpMethodReflection->getName()) + : new MethodCall($expr, $phpMethodReflection->getName()); + $innerMethodCall->args = $this->nodeFactory->createArgsFromParams($newParams); if (! $functionVariantWithPhpDoc->getReturnType() instanceof MixedType) {