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

Breadcrumb

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

function LowercaseDeclarationSniff::process

Processes this test, when one of its tokens is encountered.

Parameters

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

int $stackPtr The position of the current token in: the stack passed in $tokens.

Return value

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/ControlStructures/LowercaseDeclarationSniff.php, line 52

Class

LowercaseDeclarationSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $content = $tokens[$stackPtr]['content'];
    $contentLc = strtolower($content);
    if ($content !== $contentLc) {
        $error = '%s keyword must be lowercase; expected "%s" but found "%s"';
        $data = [
            strtoupper($content),
            $contentLc,
            $content,
        ];
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'FoundUppercase', $data);
        if ($fix === true) {
            $phpcsFile->fixer
                ->replaceToken($stackPtr, $contentLc);
        }
    }
}
RSS feed
Powered by Drupal