Skip to content

Commit 3d6b069

Browse files
committed
DataProviderDataRule: Optimize hot path
1 parent 0f6ba8e commit 3d6b069

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Rules/PHPUnit/DataProviderDataRule.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,13 @@ public function processNode(Node $node, Scope $scope): array
5858
return [];
5959
}
6060

61-
$arraysTypes = $this->buildArrayTypesFromNode($node, $scope);
62-
if ($arraysTypes === []) {
63-
return [];
64-
}
65-
66-
$method = $scope->getFunction();
6761
$classReflection = $scope->getClassReflection();
6862
if ($classReflection === null) {
6963
return [];
7064
}
7165

7266
$testsWithProvider = [];
67+
$method = $scope->getFunction();
7368
$testMethods = $this->testMethodsHelper->getTestMethods($classReflection, $scope);
7469
foreach ($testMethods as $testMethod) {
7570
foreach ($this->dataProviderHelper->getDataProviderMethods($scope, $testMethod, $classReflection) as [, $providerMethodName]) {
@@ -84,6 +79,11 @@ public function processNode(Node $node, Scope $scope): array
8479
return [];
8580
}
8681

82+
$arraysTypes = $this->buildArrayTypesFromNode($node, $scope);
83+
if ($arraysTypes === []) {
84+
return [];
85+
}
86+
8787
$maxNumberOfParameters = null;
8888
foreach ($testsWithProvider as $testMethod) {
8989
$num = $testMethod->getNumberOfParameters();

src/Rules/PHPUnit/TestMethodsHelper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ public function getTestMethodReflection(ClassReflection $classReflection, Method
4848
*/
4949
public function getTestMethods(ClassReflection $classReflection, Scope $scope): array
5050
{
51-
if (array_key_exists($classReflection->getName(), $this->methodCache)) {
52-
return $this->methodCache[$classReflection->getName()];
51+
$className = $classReflection->getName();
52+
if (array_key_exists($className, $this->methodCache)) {
53+
return $this->methodCache[$className];
5354
}
5455
if (!$classReflection->is(TestCase::class)) {
55-
return $this->methodCache[$classReflection->getName()] = [];
56+
return $this->methodCache[$className] = [];
5657
}
5758

5859
$testMethods = [];
@@ -70,7 +71,7 @@ public function getTestMethods(ClassReflection $classReflection, Scope $scope):
7071
if ($docComment !== null) {
7172
$methodPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
7273
$scope->getFile(),
73-
$classReflection->getName(),
74+
$className,
7475
$scope->isInTrait() ? $scope->getTraitReflection()->getName() : null,
7576
$reflectionMethod->getName(),
7677
$docComment,
@@ -94,7 +95,7 @@ public function getTestMethods(ClassReflection $classReflection, Scope $scope):
9495
$testMethods[] = $reflectionMethod;
9596
}
9697

97-
return $this->methodCache[$classReflection->getName()] = $testMethods;
98+
return $this->methodCache[$className] = $testMethods;
9899
}
99100

100101
private function hasTestAnnotation(?ResolvedPhpDocBlock $phpDoc): bool

0 commit comments

Comments
 (0)