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

Public Member Functions

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

Data Fields

 $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]
 
 $indent = 4
 
 $maxIndentLevel = 3
 

Detailed Description

Class IndentationSniff

Ensures styles are indented 4 spaces.

See also
Squiz_Sniffs_CSS_IndentationSniff http://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#indentation

Definition at line 19 of file IndentationSniff.php.

Member Function Documentation

◆ process()

process ( File  $phpcsFile,
  $stackPtr 
)

{} @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 61 of file IndentationSniff.php.

62  {
63  $tokens = $phpcsFile->getTokens();
64 
65  $numTokens = (count($tokens) - 2);
66  $indentLevel = 0;
67  for ($i = 1; $i < $numTokens; $i++) {
68  if ($tokens[$i]['code'] === T_COMMENT) {
69  // Don't check the indent of comments.
70  continue;
71  }
72 
73  if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
74  $indentLevel++;
75  } elseif ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) {
76  $indentLevel--;
77  }
78 
79  if ($tokens[$i]['column'] !== 1) {
80  continue;
81  }
82 
83  // We started a new line, so check indent.
84  if ($tokens[$i]['code'] === T_WHITESPACE) {
85  $content = str_replace($phpcsFile->eolChar, '', $tokens[$i]['content']);
86  $foundIndent = strlen($content);
87  } else {
88  $foundIndent = 0;
89  }
90 
91  $expectedIndent = ($indentLevel * $this->indent);
92  if (!($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false)
93  && ($foundIndent !== $expectedIndent)
94  && (!in_array($tokens[$i + 1]['code'], $this->styleCodesToSkip))
95  ) {
96  $error = 'Line indented incorrectly; expected %s spaces, found %s';
97  $phpcsFile->addError($error, $i, 'Incorrect', [$expectedIndent, $foundIndent]);
98  }
99 
100  if ($indentLevel > $this->maxIndentLevel) {
101  // Will be implemented in MAGETWO-49778
102  // $phpcsFile->addWarning('Avoid using more than three levels of nesting', $i, 'IncorrectNestingLevel');
103  }
104  }
105  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$i
Definition: gallery.phtml:31
$tokens
Definition: cards_list.phtml:9

◆ register()

register ( )

{}

Definition at line 51 of file IndentationSniff.php.

52  {
53  return [T_OPEN_TAG];
54  }

Field Documentation

◆ $indent

$indent = 4

Definition at line 33 of file IndentationSniff.php.

◆ $maxIndentLevel

$maxIndentLevel = 3

Definition at line 40 of file IndentationSniff.php.

◆ $supportedTokenizers

$supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]

Definition at line 26 of file IndentationSniff.php.


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