Skip to content

Commit cdc55c0

Browse files
authored
Merge pull request #141 from mglaman/102-drupal-static-calls
Allow \Drupal calls in traits and tests
2 parents 9d218ec + aee0027 commit cdc55c0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function processNode(Node $node, Scope $scope): array
2323
if (!($node->class instanceof Node\Name\FullyQualified) || (string) $node->class !== 'Drupal') {
2424
return [];
2525
}
26-
if (!$scope->isInClass() && !$scope->isInTrait()) {
26+
// Do not raise if called inside of a trait.
27+
if (!$scope->isInClass() || $scope->isInTrait()) {
2728
return [];
2829
}
2930
$scopeClassReflection = $scope->getClassReflection();
@@ -32,6 +33,8 @@ public function processNode(Node $node, Scope $scope): array
3233
}
3334

3435
$whitelist = [
36+
// Ignore tests.
37+
'PHPUnit\Framework\TestCase',
3538
// Typed data objects cannot use dependency injection.
3639
'Drupal\Core\TypedData\TypedDataInterface',
3740
// Render elements cannot use dependency injection.

0 commit comments

Comments
 (0)