diff --git a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 2778da8c..50f4b0b7 100644 --- a/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -11,15 +11,13 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff; -use PHP_CodeSniffer\Util\Common; /** * \Drupal\Sniffs\NamingConventions\ValidFunctionNameSniff. * * Extends * \PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff - * to also check global function names outside the scope of classes and to not - * allow methods beginning with an underscore. + * to also check global function names outside the scope of classes. * * @category PHP * @package PHP_CodeSniffer @@ -39,62 +37,6 @@ class ValidFunctionNameSniff extends CamelCapsFunctionNameSniff ]; - /** - * Processes the tokens within the scope. - * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. - * - * @return void - */ - protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) - { - $methodName = $phpcsFile->getDeclarationName($stackPtr); - if ($methodName === '') { - // Ignore closures. - return; - } - - $className = $phpcsFile->getDeclarationName($currScope); - $errorData = [$className . '::' . $methodName]; - - // Is this a magic method. i.e., is prefixed with "__" ? - if (preg_match('|^__|', $methodName) !== 0) { - $magicPart = strtolower(substr($methodName, 2)); - if (isset($this->magicMethods[$magicPart]) === false - && isset($this->methodsDoubleUnderscore[$magicPart]) === false - ) { - $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; - $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData); - } - - return; - } - - $methodProps = $phpcsFile->getMethodProperties($stackPtr); - if (Common::isCamelCaps($methodName, false, true, $this->strict) === false) { - if ($methodProps['scope_specified'] === true) { - $error = '%s method name "%s" is not in lowerCamel format'; - $data = [ - ucfirst($methodProps['scope']), - $errorData[0], - ]; - $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data); - } else { - $error = 'Method name "%s" is not in lowerCamel format'; - $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); - } - - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no'); - return; - } else { - $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes'); - } - } - - /** * Processes the tokens outside the scope. * diff --git a/tests/Drupal/bad/BadUnitTest.php b/tests/Drupal/bad/BadUnitTest.php index 538cf9bb..fd426887 100644 --- a/tests/Drupal/bad/BadUnitTest.php +++ b/tests/Drupal/bad/BadUnitTest.php @@ -267,8 +267,8 @@ protected function getErrorList(string $testFile): array 401 => 1, 403 => 1, 406 => 2, - 407 => 3, - 411 => 2, + 407 => 2, + 411 => 1, 417 => 1, 418 => 2, 421 => 1,