Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
ColourDefinitionSniff Class Reference
Inheritance diagram for ColourDefinitionSniff:

Public Member Functions

 register ()
 
 process (File $phpcsFile, $stackPtr)
 

Data Fields

 $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]
 

Detailed Description

Class ColourDefinitionSniff

Ensure that hexadecimal values are used for variables not for properties

http://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#hexadecimal-notation

Definition at line 19 of file ColourDefinitionSniff.php.

Member Function Documentation

◆ process()

process ( File  $phpcsFile,
  $stackPtr 
)

{}

Definition at line 39 of file ColourDefinitionSniff.php.

40  {
41  $tokens = $phpcsFile->getTokens();
42  $colour = $tokens[$stackPtr]['content'];
43 
44  $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr);
45  if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) {
46  $phpcsFile->addError('Hexadecimal value should be used for variable', $stackPtr, 'NotInVariable');
47  }
48 
49  $expected = strtolower($colour);
50  if ($colour !== $expected) {
51  $error = 'CSS colours must be defined in lowercase; expected %s but found %s';
52  $phpcsFile->addError($error, $stackPtr, 'NotLower', [$expected, $colour]);
53  }
54 
55  // Now check if shorthand can be used.
56  if (strlen($colour) !== 7) {
57  return;
58  }
59 
60  if ($colour[1] === $colour[2] && $colour[3] === $colour[4] && $colour[5] === $colour[6]) {
61  $expected = '#' . $colour[1] . $colour[3] . $colour[5];
62  $error = 'CSS colours must use shorthand if available; expected %s but found %s';
63  $phpcsFile->addError($error, $stackPtr, 'Shorthand', [$expected, $colour]);
64  }
65  }
$tokens
Definition: cards_list.phtml:9

◆ register()

register ( )

{}

Definition at line 31 of file ColourDefinitionSniff.php.

32  {
33  return [T_COLOUR];
34  }

Field Documentation

◆ $supportedTokenizers

$supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]

Definition at line 26 of file ColourDefinitionSniff.php.


The documentation for this class was generated from the following file: