3
* Squiz_Sniffs_CSS_NamedColoursSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
11
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12
* @link http://pear.php.net/package/PHP_CodeSniffer
16
* Squiz_Sniffs_CSS_NamedColoursSniff.
18
* Ensure colour names are not used.
21
* @package PHP_CodeSniffer
22
* @author Greg Sherwood <gsherwood@squiz.net>
23
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
24
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
25
* @version Release: 1.5.4
26
* @link http://pear.php.net/package/PHP_CodeSniffer
28
class Squiz_Sniffs_CSS_NamedColoursSniff implements PHP_CodeSniffer_Sniff
32
* A list of tokenizers this sniff supports.
36
public $supportedTokenizers = array('CSS');
40
* A list of named colours.
42
* This is the list of standard colours defined in the CSS spec.
46
public $colourNames = array(
68
* Returns the token types that this sniff is interested in.
72
public function register()
74
return array(T_STRING);
80
* Processes the tokens that this sniff is interested in.
82
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
83
* @param int $stackPtr The position in the stack where
84
* the token was found.
88
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
90
$tokens = $phpcsFile->getTokens();
92
if ($tokens[($stackPtr - 1)]['code'] === T_HASH
93
|| $tokens[($stackPtr - 1)]['code'] === T_STRING_CONCAT
99
if (in_array(strtolower($tokens[$stackPtr]['content']), $this->colourNames) === true) {
100
$error = 'Named colours are forbidden; use hex, rgb, or rgba values instead';
101
$phpcsFile->addError($error, $stackPtr, 'Forbidden');