diff --git a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php index 940fc9c523bec182b02a16dca97918ee6624b688..275d43c8ab7e9e3243c35487f4db033c310238e5 100644 --- a/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php +++ b/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php @@ -79,7 +79,10 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionSniff implements PHP_CodeSniff $classPtr = key($tokens[$stackPtr]['conditions']); $extendsName = $phpcsFile->findExtendedClassName($classPtr); - if ($extendsName === false || in_array($extendsName, DrupalPractice_Sniffs_Objects_GlobalDrupalSniff::$baseClasses) === false) { + if (($extendsName === false + || in_array($extendsName, DrupalPractice_Sniffs_Objects_GlobalDrupalSniff::$baseClasses) === false) + && DrupalPractice_Project::isServiceClass($phpcsFile, $classPtr) === false + ) { return; } diff --git a/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php b/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php index 5ffcb9448e0d7192bd61a028eb55f07896b4c2a1..a5857e41520f86ec1d5885e8b8a57666474de809 100644 --- a/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php +++ b/coder_sniffer/DrupalPractice/Test/Objects/GlobalFunctionUnitTest.php @@ -29,9 +29,24 @@ class DrupalPractice_Sniffs_Objects_GlobalFunctionUnitTest extends CoderSniffUni */ protected function getWarningList($testFile) { - return array(6 => 1); + switch ($testFile) { + case 'GlobalFunctionUnitTest.inc': + return array(6 => 1); + case 'ExampleService.php': + return array(30 => 1); + } }//end getWarningList() + /** + * Returns a list of test files that should be checked. + * + * @return array The list of test files. + */ + protected function getTestFiles() { + return [__DIR__.'/GlobalFunctionUnitTest.inc', __DIR__.'/src/ExampleService.php']; + } + + }//end class diff --git a/coder_sniffer/DrupalPractice/Test/Objects/src/ExampleService.php b/coder_sniffer/DrupalPractice/Test/Objects/src/ExampleService.php index 8046abd428de5e5263ccec1c0942577ab05a66db..8b8acfcf91294931f293f35445ea8629292762ca 100644 --- a/coder_sniffer/DrupalPractice/Test/Objects/src/ExampleService.php +++ b/coder_sniffer/DrupalPractice/Test/Objects/src/ExampleService.php @@ -23,4 +23,11 @@ class ExampleService { return Node::load(1); } + /** + * t() should not be used, translation service should be injected. + */ + public function test3() { + return t('Test'); + } + }