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

Breadcrumb

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

function CamelCapsFunctionNameSniff::processTokenOutsideScope

Processes the tokens outside the scope.

Parameters

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

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

Return value

void

Overrides AbstractScopeSniff::processTokenOutsideScope

2 methods override CamelCapsFunctionNameSniff::processTokenOutsideScope()
CamelCapsMethodNameSniff::processTokenOutsideScope in vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php
Processes the tokens outside the scope.
ValidFunctionNameSniff::processTokenOutsideScope in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidFunctionNameSniff.php
Processes the tokens outside the scope.

File

vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php, line 187

Class

CamelCapsFunctionNameSniff

Namespace

PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions

Code

protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) {
    $functionName = $phpcsFile->getDeclarationName($stackPtr);
    if ($functionName === null) {
        // Live coding or parse error. Bow out.
        return;
    }
    $errorData = [
        $functionName,
    ];
    // Is this a magic function. i.e., it is prefixed with "__".
    if (preg_match('|^__[^_]|', $functionName) !== 0) {
        $magicPart = strtolower(substr($functionName, 2));
        if (isset($this->magicFunctions[$magicPart]) === true) {
            return;
        }
        $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
        $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
    }
    // Ignore leading underscores in the method name.
    $functionName = ltrim($functionName, '_');
    if (Common::isCamelCaps($functionName, false, true, $this->strict) === false) {
        $error = 'Function name "%s" is not in camel caps format';
        $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
        $phpcsFile->recordMetric($stackPtr, 'CamelCase function 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