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

Public Member Functions

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

Data Fields

 $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]
 

Detailed Description

Class VariablesSniff

Ensure that the variables are responds to the following requirements:

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

Definition at line 23 of file VariablesSniff.php.

Member Function Documentation

◆ process()

process ( File  $phpcsFile,
  $stackPtr 
)

{}

Definition at line 43 of file VariablesSniff.php.

44  {
45  $tokens = $phpcsFile->getTokens();
46  $currentToken = $tokens[$stackPtr];
47 
48  $nextColon = $phpcsFile->findNext(T_COLON, $stackPtr);
49  $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
50  if ((false === $nextColon) || (false === $nextSemicolon)) {
51  return;
52  }
53 
54  $isVariableDeclaration = ($currentToken['line'] === $tokens[$nextColon]['line'])
55  && ($currentToken['line'] === $tokens[$nextSemicolon]['line'])
56  && (T_STRING === $tokens[$stackPtr + 1]['code'])
57  && (T_COLON === $tokens[$stackPtr + 2]['code']);
58 
59  if (!$isVariableDeclaration) {
60  return;
61  }
62 
63  $classBefore = $phpcsFile->findPrevious(T_STYLE, $stackPtr);
64  if (false !== $classBefore) {
65  $phpcsFile->addError(
66  'Variable declaration located not in the beginning of general comments',
67  $stackPtr,
68  'VariableLocation'
69  );
70  }
71 
72  $variableName = $tokens[$stackPtr + 1]['content'];
73  if (preg_match('/[A-Z]/', $variableName)) {
74  $phpcsFile->addError(
75  'Variable declaration contains uppercase symbols',
76  $stackPtr,
77  'VariableUppercase'
78  );
79  }
80  }
$tokens
Definition: cards_list.phtml:9

◆ register()

register ( )

{}

Definition at line 35 of file VariablesSniff.php.

36  {
37  return [T_ASPERAND];
38  }

Field Documentation

◆ $supportedTokenizers

$supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]

Definition at line 30 of file VariablesSniff.php.


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