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

Breadcrumb

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

function CamelCapsMethodNameSniff::processTokenWithinScope

Processes the tokens within the scope.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being processed.:

int $stackPtr The position where this token was: found.

int $currScope The position of the current scope.:

Return value

void

Overrides CamelCapsFunctionNameSniff::processTokenWithinScope

File

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

Class

CamelCapsMethodNameSniff

Namespace

PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods

Code

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');
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal