3
* Squiz_Sniffs_CSS_MissingColonSniff.
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_MissingColonSniff.
18
* Ensure that all style definitions have a colon.
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_MissingColonSniff implements PHP_CodeSniffer_Sniff
32
* A list of tokenizers this sniff supports.
36
public $supportedTokenizers = array('CSS');
40
* Returns the token types that this sniff is interested in.
44
public function register()
46
return array(T_OPEN_CURLY_BRACKET);
52
* Processes the tokens that this sniff is interested in.
54
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
55
* @param int $stackPtr The position in the stack where
56
* the token was found.
60
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
$tokens = $phpcsFile->getTokens();
63
$lastLine = $tokens[$stackPtr]['line'];
64
$end = $tokens[$stackPtr]['bracket_closer'];
65
$endLine = $tokens[$end]['line'];
67
// Do not check nested style definitions as, for example, in @media style rules.
68
$nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $end);
69
if ($nested !== false) {
75
for ($i = ($stackPtr + 1); $i <= $end; $i++) {
76
if ($tokens[$i]['line'] !== $lastLine) {
78
if ($foundColon === false && $foundString !== false) {
79
// We didn't find a colon on the previous line.
80
$error = 'No style definition found on line; check for missing colon';
81
$phpcsFile->addError($error, $foundString, 'Found');
86
$lastLine = $tokens[$i]['line'];
89
if ($tokens[$i]['code'] === T_STRING) {
91
} else if ($tokens[$i]['code'] === T_COLON) {