Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /** | |
3 * Drupal_Sniffs_CSS_ColourDefinitionSniff. | |
4 * | |
5 * @category PHP | |
6 * @package PHP_CodeSniffer | |
7 * @link http://pear.php.net/package/PHP_CodeSniffer | |
8 */ | |
9 | |
10 /** | |
11 * Squiz_Sniffs_CSS_ColourDefinitionSniff. | |
12 * | |
13 * Ensure colours are defined in lower-case. | |
14 * | |
15 * @category PHP | |
16 * @package PHP_CodeSniffer | |
17 * @link http://pear.php.net/package/PHP_CodeSniffer | |
18 */ | |
19 class Drupal_Sniffs_CSS_ColourDefinitionSniff implements PHP_CodeSniffer_Sniff | |
20 { | |
21 | |
22 /** | |
23 * A list of tokenizers this sniff supports. | |
24 * | |
25 * @var array | |
26 */ | |
27 public $supportedTokenizers = array('CSS'); | |
28 | |
29 | |
30 /** | |
31 * Returns the token types that this sniff is interested in. | |
32 * | |
33 * @return array(int) | |
34 */ | |
35 public function register() | |
36 { | |
37 return array(T_COLOUR); | |
38 | |
39 }//end register() | |
40 | |
41 | |
42 /** | |
43 * Processes the tokens that this sniff is interested in. | |
44 * | |
45 * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. | |
46 * @param int $stackPtr The position in the stack where | |
47 * the token was found. | |
48 * | |
49 * @return void | |
50 */ | |
51 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
52 { | |
53 $tokens = $phpcsFile->getTokens(); | |
54 $colour = $tokens[$stackPtr]['content']; | |
55 | |
56 $expected = strtolower($colour); | |
57 if ($colour !== $expected) { | |
58 $error = 'CSS colours must be defined in lowercase; expected %s but found %s'; | |
59 $data = array( | |
60 $expected, | |
61 $colour, | |
62 ); | |
63 $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data); | |
64 if ($fix === true) { | |
65 $phpcsFile->fixer->replaceToken($stackPtr, $expected); | |
66 } | |
67 } | |
68 | |
69 }//end process() | |
70 | |
71 | |
72 }//end class |