From c8622a279264b28d9e1336dbb0cb2e8f72b3c6c4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 10 Aug 2026 15:08:22 +0200 Subject: [PATCH 1/3] RuntimeReflectionFunctionRule: cheap checks first --- src/Rules/Api/RuntimeReflectionFunctionRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rules/Api/RuntimeReflectionFunctionRule.php b/src/Rules/Api/RuntimeReflectionFunctionRule.php index b46f7c7b364..43d812ae91d 100644 --- a/src/Rules/Api/RuntimeReflectionFunctionRule.php +++ b/src/Rules/Api/RuntimeReflectionFunctionRule.php @@ -35,6 +35,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if (!$scope->isInClass()) { + return []; + } + if (!$this->reflectionProvider->hasFunction($node->name, $scope)) { return []; } @@ -50,10 +54,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - if (!$scope->isInClass()) { - return []; - } - $classReflection = $scope->getClassReflection(); $hasPhpStanInterface = false; foreach (array_keys($classReflection->getInterfaces()) as $interfaceName) { From cc4adb863707c54fe99649315e36277be56c0dfb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 10 Aug 2026 15:11:24 +0200 Subject: [PATCH 2/3] Update RuntimeReflectionInstantiationRule.php --- src/Rules/Api/RuntimeReflectionInstantiationRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rules/Api/RuntimeReflectionInstantiationRule.php b/src/Rules/Api/RuntimeReflectionInstantiationRule.php index ab3ae254fc1..065ed554ca3 100644 --- a/src/Rules/Api/RuntimeReflectionInstantiationRule.php +++ b/src/Rules/Api/RuntimeReflectionInstantiationRule.php @@ -45,6 +45,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if (!$scope->isInClass()) { + return []; + } + $className = $scope->resolveName($node->class); if (!$this->reflectionProvider->hasClass($className)) { return []; @@ -69,10 +73,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - if (!$scope->isInClass()) { - return []; - } - $scopeClassReflection = $scope->getClassReflection(); $hasPhpStanInterface = false; foreach (array_keys($scopeClassReflection->getInterfaces()) as $interfaceName) { From d341245acdea9584a6fd2cfcbe883c1c210cbee5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 10 Aug 2026 15:13:39 +0200 Subject: [PATCH 3/3] cheap --- src/Rules/Api/NodeConnectingVisitorAttributesRule.php | 10 ++++++---- src/Rules/Api/OldPhpParser4ClassRule.php | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Rules/Api/NodeConnectingVisitorAttributesRule.php b/src/Rules/Api/NodeConnectingVisitorAttributesRule.php index 135a97465f6..823be3fee97 100644 --- a/src/Rules/Api/NodeConnectingVisitorAttributesRule.php +++ b/src/Rules/Api/NodeConnectingVisitorAttributesRule.php @@ -34,15 +34,17 @@ public function processNode(Node $node, Scope $scope): array if ($node->name->toLowerString() !== 'getattribute') { return []; } - $calledOnType = $scope->getType($node->var); - if (!(new ObjectType(Node::class))->isSuperTypeOf($calledOnType)->yes()) { - return []; - } + $args = $node->getArgs(); if (!isset($args[0])) { return []; } + $calledOnType = $scope->getType($node->var); + if (!(new ObjectType(Node::class))->isSuperTypeOf($calledOnType)->yes()) { + return []; + } + $messages = []; $argType = $scope->getType($args[0]->value); foreach ($argType->getConstantStrings() as $constantString) { diff --git a/src/Rules/Api/OldPhpParser4ClassRule.php b/src/Rules/Api/OldPhpParser4ClassRule.php index 8d36cc0f9ae..8919cb2c0a1 100644 --- a/src/Rules/Api/OldPhpParser4ClassRule.php +++ b/src/Rules/Api/OldPhpParser4ClassRule.php @@ -42,6 +42,10 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { + if (!$scope->isInClass()) { + return []; + } + $nameMapping = array_change_key_case(self::NAME_MAPPING); $lowerName = $node->toLowerString(); if (!array_key_exists($lowerName, $nameMapping)) { @@ -50,10 +54,6 @@ public function processNode(Node $node, Scope $scope): array $newName = $nameMapping[$lowerName]; - if (!$scope->isInClass()) { - return []; - } - $classReflection = $scope->getClassReflection(); $hasPhpStanInterface = false; foreach (array_keys($classReflection->getInterfaces()) as $interfaceName) {