Chris@0: getDeclarationName($stackPtr); Chris@0: if ($methodName === null) { Chris@0: // Ignore closures. Chris@0: return; Chris@0: } Chris@0: Chris@0: $className = $phpcsFile->getDeclarationName($currScope); Chris@0: $errorData = array($className.'::'.$methodName); Chris@0: Chris@0: // Is this a magic method. i.e., is prefixed with "__" ? Chris@0: if (preg_match('|^__|', $methodName) !== 0) { Chris@0: $magicPart = strtolower(substr($methodName, 2)); Chris@0: if (isset($this->magicMethods[$magicPart]) === false Chris@0: && isset($this->methodsDoubleUnderscore[$magicPart]) === false Chris@0: ) { Chris@0: $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore'; Chris@0: $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData); Chris@0: } Chris@0: Chris@0: return; Chris@0: } Chris@0: Chris@0: $methodProps = $phpcsFile->getMethodProperties($stackPtr); Chris@17: if (Common::isCamelCaps($methodName, false, true, $this->strict) === false) { Chris@0: if ($methodProps['scope_specified'] === true) { Chris@0: $error = '%s method name "%s" is not in lowerCamel format'; Chris@0: $data = array( Chris@0: ucfirst($methodProps['scope']), Chris@0: $errorData[0], Chris@0: ); Chris@0: $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data); Chris@0: } else { Chris@0: $error = 'Method name "%s" is not in lowerCamel format'; Chris@0: $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData); Chris@0: } Chris@0: Chris@0: $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no'); Chris@0: return; Chris@0: } else { Chris@0: $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes'); Chris@0: } Chris@0: Chris@0: }//end processTokenWithinScope() Chris@0: Chris@0: Chris@0: /** Chris@0: * Processes the tokens outside the scope. Chris@0: * Chris@17: * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. Chris@17: * @param int $stackPtr The position where this token was Chris@17: * found. Chris@0: * Chris@0: * @return void Chris@0: */ Chris@17: protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) Chris@0: { Chris@0: $functionName = $phpcsFile->getDeclarationName($stackPtr); Chris@0: if ($functionName === null) { Chris@0: // Ignore closures. Chris@0: return; Chris@0: } Chris@0: Chris@0: $isApiFile = substr($phpcsFile->getFilename(), -8) === '.api.php'; Chris@0: $isHookExample = substr($functionName, 0, 5) === 'hook_'; Chris@0: if ($isApiFile === true && $isHookExample === true) { Chris@0: // Ignore for examaple hook_ENTITY_TYPE_insert() functions in .api.php Chris@0: // files. Chris@0: return; Chris@0: } Chris@0: Chris@0: if ($functionName !== strtolower($functionName)) { Chris@0: $expected = strtolower(preg_replace('/([^_])([A-Z])/', '$1_$2', $functionName)); Chris@0: $error = 'Invalid function name, expected %s but found %s'; Chris@0: $data = array( Chris@0: $expected, Chris@0: $functionName, Chris@0: ); Chris@0: $phpcsFile->addError($error, $stackPtr, 'InvalidName', $data); Chris@0: } Chris@0: Chris@0: }//end processTokenOutsideScope() Chris@0: Chris@0: Chris@0: }//end class