You are here

public function ColourDefinitionSniff::process in Coder 8.3.x

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php \Drupal\Sniffs\CSS\ColourDefinitionSniff::process()
  2. 8.2 coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php \Drupal\Sniffs\CSS\ColourDefinitionSniff::process()

Processes the tokens that this sniff is interested in.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.:

int $stackPtr The position in the stack where: the token was found.

Return value

void

File

coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php, line 56

Class

ColourDefinitionSniff
\Drupal\Sniffs\CSS\ColourDefinitionSniff.

Namespace

Drupal\Sniffs\CSS

Code

public function process(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  $colour = $tokens[$stackPtr]['content'];
  $expected = strtolower($colour);
  if ($colour !== $expected) {
    $error = 'CSS colours must be defined in lowercase; expected %s but found %s';
    $data = [
      $expected,
      $colour,
    ];
    $fix = $phpcsFile
      ->addFixableError($error, $stackPtr, 'NotLower', $data);
    if ($fix === true) {
      $phpcsFile->fixer
        ->replaceToken($stackPtr, $expected);
    }
  }
}