diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php index 4148ba8e..4d0ac1f3 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalDrupalSniff.php @@ -95,8 +95,13 @@ public function process(File $phpcsFile, $stackPtr) $extendsName = $phpcsFile->findExtendedClassName($classPtr); // Check if the class implements ContainerInjectionInterface. + $containerInterfaces = [ + 'ContainerInjectionInterface', + 'ContainerFactoryPluginInterface', + 'ContainerDeriverInterface', + ]; $implementedInterfaceNames = $phpcsFile->findImplementedInterfaceNames($classPtr); - $canAccessContainer = !empty($implementedInterfaceNames) && in_array('ContainerInjectionInterface', $implementedInterfaceNames); + $canAccessContainer = !empty($implementedInterfaceNames) && !empty(array_intersect($containerInterfaces, $implementedInterfaceNames)); if (($extendsName === false || in_array($extendsName, static::$baseClasses) === false) && Project::isServiceClass($phpcsFile, $classPtr) === false