Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function processNode(Node $node, Scope $scope): array
if (!($node->class instanceof Node\Name\FullyQualified) || (string) $node->class !== 'Drupal') {
return [];
}
if (!$scope->isInClass() && !$scope->isInTrait()) {
// Do not raise if called inside of a trait.
if (!$scope->isInClass() || $scope->isInTrait()) {
return [];
}
$scopeClassReflection = $scope->getClassReflection();
Expand All @@ -32,6 +33,8 @@ public function processNode(Node $node, Scope $scope): array
}

$whitelist = [
// Ignore tests.
'PHPUnit\Framework\TestCase',
// Typed data objects cannot use dependency injection.
'Drupal\Core\TypedData\TypedDataInterface',
// Render elements cannot use dependency injection.
Expand Down