Skip to content

Commit 623a8fb

Browse files
authored
Merge pull request #323 from neclimdul/default-theme-rule-perf
Optimize BrowserTestBaseDefaultThemeRule
2 parents 2e77ef2 + 36a2a7d commit 623a8fb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ public function processNode(Node $node, Scope $scope): array
3434
return [];
3535
}
3636

37+
// Only inspect tests.
38+
// @todo replace this str_ends_with() when php 8 is required.
39+
if (0 !== substr_compare($node->namespacedName->getLast(), 'Test', -4)) {
40+
return [];
41+
}
42+
43+
// Do some cheap preflight tests to make sure the class is in a
44+
// namespace that makes sense to inspect.
45+
$parts = $node->namespacedName->parts;
46+
// The namespace is too short to be a test so skip inspection.
47+
if (count($parts) < 3) {
48+
return [];
49+
}
50+
// If the 4th component matches it's a module test. If the 2nd, core.
51+
if ($parts[3] !== 'Functional'
52+
&& $parts [3] !== 'FunctionalJavascript'
53+
&& $parts[1] !== 'FunctionalTests'
54+
&& $parts[1] !== 'FunctionalJavascriptTests') {
55+
return [];
56+
}
57+
58+
3759
$classType = $scope->resolveTypeByName($node->namespacedName);
3860
assert($classType instanceof ObjectType);
3961

0 commit comments

Comments
 (0)