Skip to content

Commit 36a2a7d

Browse files
committed
Optimize BrowserTestBaseDefaultThemeRule
Avoid inspecting classes we know aren't tests or Functional/Browser tests.
1 parent d18007f commit 36a2a7d

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
@@ -30,6 +30,28 @@ public function processNode(Node $node, Scope $scope): array
3030
return [];
3131
}
3232

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

0 commit comments

Comments
 (0)