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

Breadcrumb

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

function BrowserSpecificStylesSniff::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

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php, line 66

Class

BrowserSpecificStylesSniff

Namespace

PHP_CodeSniffer\Standards\MySource\Sniffs\CSS

Code

public function process(File $phpcsFile, $stackPtr) {
    // Ignore files with browser-specific suffixes.
    $filename = $phpcsFile->getFilename();
    $breakChar = strrpos($filename, '_');
    if ($breakChar !== false && substr($filename, -4) === '.css') {
        $specific = substr($filename, $breakChar + 1, -4);
        if (isset($this->specificStylesheets[$specific]) === true) {
            return;
        }
    }
    $tokens = $phpcsFile->getTokens();
    $content = $tokens[$stackPtr]['content'];
    if ($content[0] === '-') {
        $error = 'Browser-specific styles are not allowed';
        $phpcsFile->addError($error, $stackPtr, 'ForbiddenStyle');
    }
}
RSS feed
Powered by Drupal