diff --git a/Magento/Sniffs/Functions/StaticFunctionSniff.php b/Magento/Sniffs/Functions/StaticFunctionSniff.php new file mode 100644 index 00000000..2a6e537f --- /dev/null +++ b/Magento/Sniffs/Functions/StaticFunctionSniff.php @@ -0,0 +1,59 @@ +findNext(T_FUNCTION, $stackPtr) + 1; + $tokens = array_slice($phpcsFile->getTokens(), $stackPtr, $posOfFunction - $stackPtr); + + $allowedTypes = [T_STATIC => true, T_WHITESPACE => true, T_FUNCTION => true]; + foreach ($tokens as $token) { + $code = $token['code']; + if (!array_key_exists($code, $allowedTypes)) { + break; + } + + if ($code === T_FUNCTION) { + $phpcsFile->addWarning($this->warningMessage, $posOfFunction, $this->warningCode); + } + } + } +} diff --git a/Magento/Tests/Functions/StaticFunctionUnitTest.inc b/Magento/Tests/Functions/StaticFunctionUnitTest.inc new file mode 100644 index 00000000..d07cc6fc --- /dev/null +++ b/Magento/Tests/Functions/StaticFunctionUnitTest.inc @@ -0,0 +1,26 @@ + 1, + 17 => 1 + ]; + } +} diff --git a/Magento/ruleset.xml b/Magento/ruleset.xml index b260bad4..e85c2930 100644 --- a/Magento/ruleset.xml +++ b/Magento/ruleset.xml @@ -72,6 +72,9 @@ 8 + + 6 +