getTokens(); $colour = $tokens[$stackPtr]['content']; $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { $phpcsFile->addError('Hexadecimal value should be used for variable', $stackPtr, 'NotInVariable'); } $expected = strtolower($colour); if ($colour !== $expected) { $error = 'CSS colours must be defined in lowercase; expected %s but found %s'; $phpcsFile->addError($error, $stackPtr, 'NotLower', [$expected, $colour]); } // Now check if shorthand can be used. if (strlen($colour) !== 7) { return; } if ($colour[1] === $colour[2] && $colour[3] === $colour[4] && $colour[5] === $colour[6]) { $expected = '#' . $colour[1] . $colour[3] . $colour[5]; $error = 'CSS colours must use shorthand if available; expected %s but found %s'; $phpcsFile->addError($error, $stackPtr, 'Shorthand', [$expected, $colour]); } } }