Chris@0: findFirstOnLine(T_DOC_COMMENT_TAG, ($stackPtr - 1)); Chris@0: if ($doc_comment_tag !== false) { Chris@0: // Allow doc comment tags such as long @param tags to exceed the 80 Chris@0: // character limit. Chris@0: return; Chris@0: } Chris@0: Chris@0: if ($tokens[($stackPtr - 1)]['code'] === T_COMMENT Chris@0: // Allow @link and @see documentation to exceed the 80 character Chris@0: // limit. Chris@0: && (preg_match('/^[[:space:]]*\/\/ @.+/', $tokens[($stackPtr - 1)]['content']) === 1 Chris@0: // Allow anything that does not contain spaces (like URLs) to be Chris@0: // longer. Chris@0: || strpos(trim($tokens[($stackPtr - 1)]['content'], "/ \n"), ' ') === false) Chris@0: ) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Code examples between @code and @endcode are allowed to exceed 80 Chris@0: // characters. Chris@0: if (isset($tokens[$stackPtr]) === true && $tokens[$stackPtr]['code'] === T_DOC_COMMENT_WHITESPACE) { Chris@0: $tag = $phpcsFile->findPrevious(array(T_DOC_COMMENT_TAG, T_DOC_COMMENT_OPEN_TAG), ($stackPtr - 1)); Chris@0: if ($tokens[$tag]['content'] === '@code') { Chris@0: return; Chris@0: } Chris@0: } Chris@0: Chris@0: // Drupal 8 annotations can have long translatable descriptions and we Chris@0: // allow them to exceed 80 characters. Chris@0: if ($tokens[($stackPtr - 2)]['code'] === T_DOC_COMMENT_STRING Chris@0: && (strpos($tokens[($stackPtr - 2)]['content'], '@Translation(') !== false Chris@0: // Also allow anything without whitespace (like URLs) to exceed 80 Chris@0: // characters. Chris@0: || strpos($tokens[($stackPtr - 2)]['content'], ' ') === false Chris@0: // Allow long "Contains ..." comments in @file doc blocks. Chris@0: || preg_match('/^Contains [a-zA-Z_\\\\.]+$/', $tokens[($stackPtr - 2)]['content']) === 1 Chris@0: // Allow long paths or namespaces in annotations such as Chris@0: // "list_builder" = "Drupal\rules\Entity\Controller\RulesReactionListBuilder" Chris@0: // cardinality = \Drupal\webform\WebformHandlerInterface::CARDINALITY_UNLIMITED. Chris@0: || preg_match('#= ("|\')?\S+[\\\\/]\S+("|\')?,*$#', $tokens[($stackPtr - 2)]['content']) === 1) Chris@0: // Allow @link tags in lists. Chris@0: || strpos($tokens[($stackPtr - 2)]['content'], '- @link') !== false Chris@0: // Allow hook implementation line to exceed 80 characters. Chris@0: || preg_match('/^Implements hook_[a-zA-Z0-9_]+\(\)/', $tokens[($stackPtr - 2)]['content']) === 1 Chris@0: ) { Chris@0: return; Chris@0: } Chris@0: Chris@0: parent::checkLineLength($phpcsFile, $tokens, $stackPtr); Chris@0: }//end if Chris@0: Chris@0: }//end checkLineLength() Chris@0: Chris@0: Chris@0: /** Chris@0: * Returns the length of a defined line. Chris@0: * Chris@17: * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. Chris@17: * @param int $currentLine The current line. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@17: public function getLineLength(File $phpcsFile, $currentLine) Chris@0: { Chris@0: $tokens = $phpcsFile->getTokens(); Chris@0: Chris@0: $tokenCount = 0; Chris@0: $currentLineContent = ''; Chris@0: Chris@0: $trim = (strlen($phpcsFile->eolChar) * -1); Chris@0: for (; $tokenCount < $phpcsFile->numTokens; $tokenCount++) { Chris@0: if ($tokens[$tokenCount]['line'] === $currentLine) { Chris@0: $currentLineContent .= $tokens[$tokenCount]['content']; Chris@0: } Chris@0: } Chris@0: Chris@0: return strlen($currentLineContent); Chris@0: Chris@0: }//end getLineLength() Chris@0: Chris@0: Chris@0: }//end class