getTokens(); $numTokens = (count($tokens) - 2); $indentLevel = 0; for ($i = 1; $i < $numTokens; $i++) { if ($tokens[$i]['code'] === T_COMMENT) { // Don't check the indent of comments. continue; } if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) { $indentLevel++; } elseif ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) { $indentLevel--; } if ($tokens[$i]['column'] !== 1) { continue; } // We started a new line, so check indent. if ($tokens[$i]['code'] === T_WHITESPACE) { $content = str_replace($phpcsFile->eolChar, '', $tokens[$i]['content']); $foundIndent = strlen($content); } else { $foundIndent = 0; } $expectedIndent = ($indentLevel * $this->indent); if (!($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) && ($foundIndent !== $expectedIndent) && (!in_array($tokens[$i + 1]['code'], $this->styleCodesToSkip)) ) { $error = 'Line indented incorrectly; expected %s spaces, found %s'; $phpcsFile->addError($error, $i, 'Incorrect', [$expectedIndent, $foundIndent]); } if ($indentLevel > $this->maxIndentLevel) { // Will be implemented in MAGETWO-49778 // $phpcsFile->addWarning('Avoid using more than three levels of nesting', $i, 'IncorrectNestingLevel'); } } } }