Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CamelCapsMethodNameSniff.php

class CamelCapsMethodNameSniff

Hierarchy

  • class \PHP_CodeSniffer\Sniffs\AbstractScopeSniff implements \PHP_CodeSniffer\Sniffs\Sniff
    • class \PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff extends \PHP_CodeSniffer\Sniffs\AbstractScopeSniff
      • class \PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff extends \PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff

Expanded class hierarchy of CamelCapsMethodNameSniff

File

vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php, line 16

Namespace

PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods
View source
class CamelCapsMethodNameSniff extends GenericCamelCapsFunctionNameSniff {
    
    /**
     * 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) {
        $tokens = $phpcsFile->getTokens();
        // Determine if this is a function which needs to be examined.
        $conditions = $tokens[$stackPtr]['conditions'];
        end($conditions);
        $deepestScope = key($conditions);
        if ($deepestScope !== $currScope) {
            return;
        }
        $methodName = $phpcsFile->getDeclarationName($stackPtr);
        if ($methodName === null) {
            // Ignore closures.
            return;
        }
        // Ignore magic methods.
        if (preg_match('|^__[^_]|', $methodName) !== 0) {
            $magicPart = strtolower(substr($methodName, 2));
            if (isset($this->magicMethods[$magicPart]) === true || isset($this->methodsDoubleUnderscore[$magicPart]) === true) {
                return;
            }
        }
        $testName = ltrim($methodName, '_');
        if ($testName !== '' && Common::isCamelCaps($testName, false, true, false) === false) {
            $error = 'Method name "%s" is not in camel caps format';
            $className = $phpcsFile->getDeclarationName($currScope);
            if (isset($className) === false) {
                $className = '[Anonymous Class]';
            }
            $errorData = [
                $className . '::' . $methodName,
            ];
            $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
        }
        else {
            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
        }
    }
    
    //end processTokenWithinScope()
    
    /**
     * Processes the tokens outside the scope.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed.
     * @param int                         $stackPtr  The position where this token was
     *                                               found.
     *
     * @return void
     */
    protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) {
    }
    
    //end processTokenOutsideScope()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractScopeSniff::$listenOutside private property True if this test should fire on tokens outside of the scope.
AbstractScopeSniff::$scopeTokens private property The type of scope opener tokens that this test wishes to listen to.
AbstractScopeSniff::$tokens private property The token types that this test wishes to listen to within the scope.
AbstractScopeSniff::process final public function Processes the tokens that this test is listening for. Overrides Sniff::process
AbstractScopeSniff::register final public function The method that is called to register the tokens this test wishes to
listen to.
Overrides Sniff::register
CamelCapsFunctionNameSniff::$magicFunctions protected property A list of all PHP magic functions.
CamelCapsFunctionNameSniff::$magicMethods protected property A list of all PHP magic methods.
CamelCapsFunctionNameSniff::$methodsDoubleUnderscore protected property A list of all PHP non-magic methods starting with a double underscore.
CamelCapsFunctionNameSniff::$strict public property If TRUE, the string must not have two capital letters next to each other.
CamelCapsFunctionNameSniff::__construct public function Constructs a Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff. Overrides AbstractScopeSniff::__construct
CamelCapsMethodNameSniff::processTokenOutsideScope protected function Processes the tokens outside the scope. Overrides CamelCapsFunctionNameSniff::processTokenOutsideScope
CamelCapsMethodNameSniff::processTokenWithinScope protected function Processes the tokens within the scope. Overrides CamelCapsFunctionNameSniff::processTokenWithinScope
RSS feed
Powered by Drupal