getDeclarationName($stackPtr); if ($methodName === null) { // Ignore closures. return; } $className = $phpcsFile->getDeclarationName($currScope); $errorData = array($className . '::' . $methodName); // PHP4 constructors are allowed to break our rules. if ($methodName === $className) { return; } // PHP4 destructors are allowed to break our rules. if ($methodName === '_' . $className) { return; } // Ignore magic methods if (preg_match('/^__(' . implode('|', $this->_magicMethods) . ')$/', $methodName)) { return; } $methodProps = $phpcsFile->getMethodProperties($stackPtr); if ($methodProps['scope_specified'] === false) { // Let another sniffer take care of that return; } $isPublic = $methodProps['scope'] === 'public'; $isProtected = $methodProps['scope'] === 'protected'; $isPrivate = $methodProps['scope'] === 'private'; $scope = $methodProps['scope']; if ($isPublic === true) { if ($methodName[0] === '_') { $error = 'Public method name "%s" must not be prefixed with underscore'; $phpcsFile->addError($error, $stackPtr, 'PublicWithUnderscore', $errorData); return; } // Underscored public methods in controller are allowed to break our rules. if (substr($className, -10) === 'Controller') { return; } // Underscored public methods in shells are allowed to break our rules. if (substr($className, -5) === 'Shell') { return; } // Underscored public methods in tasks are allowed to break our rules. if (substr($className, -4) === 'Task') { return; } } } /** * Processes the tokens outside the scope. * * @param PHP_CodeSniffer_File $phpcsFile The file being processed. * @param integer $stackPtr The position where this token was found. * @return void */ protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { } }