PHPStan rule to enforce \Drupal::service
1 unresolved thread
1 unresolved thread
Closes #2066993
Merge request reports
Activity
25 return PropertyFetch::class; 26 } 27 28 /** 29 * {@inheritdoc} 30 */ 31 public function processNode(Node $node, Scope $scope): array { 32 $class = $scope->getClassReflection(); 33 34 if ($class === null || !$class->isSubclassOf(BrowserTestBase::class)) { 35 return []; 36 } 37 38 if ($node instanceof PropertyFetch && $node->name instanceof Node\Identifier && $node->name->name === 'container') { 39 return [ 40 RuleErrorBuilder::message('Functional tests should not access $this->container. Use \Drupal::service() instead.') Since we're flagging
$this->container
, should we recommend the direct alternative instead? Or maybe expand to mention both?Edited by Adam Bramleychanged this line in version 2 of the diff
Please register or sign in to reply