getTokens(); if (in_array($tokens[$stackPtr]['content'], $this->styleSymbolsToSkip)) { return; } $semicolonPtr = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); if ($tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) { $semicolonPtr = $phpcsFile->findNext(T_STYLE, ($stackPtr + 1), null, false, ";"); } $this->validateSemicolon($phpcsFile, $stackPtr, $tokens, $semicolonPtr); $this->validateSpaces($phpcsFile, $stackPtr, $tokens, $semicolonPtr); } /** * @param PHP_CodeSniffer_File $phpcsFile * @param int $stackPtr * @param array $tokens * @param int $semicolonPtr * @return void */ private function validateSemicolon(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) { if ((false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) && (isset($tokens[$stackPtr - 1]) && !in_array($tokens[$stackPtr - 1]['code'], $this->styleCodesToSkip)) && (T_COLON !== $tokens[$stackPtr + 1]['code']) ) { $error = 'Style definitions must end with a semicolon'; $phpcsFile->addError($error, $stackPtr, 'NotAtEnd'); } } /** * @param PHP_CodeSniffer_File $phpcsFile * @param int $stackPtr * @param array $tokens * @param int $semicolonPtr * @return void */ private function validateSpaces(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) { if (!isset($tokens[($semicolonPtr - 1)])) { return; } if ($tokens[($semicolonPtr - 1)]['code'] === T_WHITESPACE) { $length = strlen($tokens[($semicolonPtr - 1)]['content']); $error = 'Expected 0 spaces before semicolon in style definition; %s found'; $data = [$length]; $phpcsFile->addError($error, $stackPtr, 'SpaceFound', $data); } } }