comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 /** 2 /**
3 * Drupal_Sniffs_Files_LineLengthSniff. 3 * \Drupal\Sniffs\Files\LineLengthSniff.
4 * 4 *
5 * @category PHP 5 * @category PHP
6 * @package PHP_CodeSniffer 6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer 7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */ 8 */
9
10 namespace Drupal\Sniffs\Files;
11
12 use PHP_CodeSniffer\Files\File;
13 use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff as GenericLineLengthSniff;
14 use PHP_CodeSniffer\Util\Tokens;
9 15
10 /** 16 /**
11 * Checks comment lines in the file, and throws warnings if they are over 80 17 * Checks comment lines in the file, and throws warnings if they are over 80
12 * characters in length. 18 * characters in length.
13 * 19 *
14 * @category PHP 20 * @category PHP
15 * @package PHP_CodeSniffer 21 * @package PHP_CodeSniffer
16 * @link http://pear.php.net/package/PHP_CodeSniffer 22 * @link http://pear.php.net/package/PHP_CodeSniffer
17 */ 23 */
18 class Drupal_Sniffs_Files_LineLengthSniff extends Generic_Sniffs_Files_LineLengthSniff 24 class LineLengthSniff extends GenericLineLengthSniff
19 { 25 {
20 26
21 /** 27 /**
22 * The limit that the length of a line should not exceed. 28 * The limit that the length of a line should not exceed.
23 * 29 *
37 43
38 44
39 /** 45 /**
40 * Checks if a line is too long. 46 * Checks if a line is too long.
41 * 47 *
42 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 48 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
43 * @param array $tokens The token stack. 49 * @param array $tokens The token stack.
44 * @param int $stackPtr The first token on the next line. 50 * @param int $stackPtr The first token on the next line.
45 * 51 *
46 * @return void 52 * @return void
47 */ 53 */
48 protected function checkLineLength(PHP_CodeSniffer_File $phpcsFile, $tokens, $stackPtr) 54 protected function checkLineLength($phpcsFile, $tokens, $stackPtr)
49 { 55 {
50 if (isset(PHP_CodeSniffer_Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === true) { 56 if (isset(Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === true) {
51 $doc_comment_tag = $phpcsFile->findFirstOnLine(T_DOC_COMMENT_TAG, ($stackPtr - 1)); 57 $doc_comment_tag = $phpcsFile->findFirstOnLine(T_DOC_COMMENT_TAG, ($stackPtr - 1));
52 if ($doc_comment_tag !== false) { 58 if ($doc_comment_tag !== false) {
53 // Allow doc comment tags such as long @param tags to exceed the 80 59 // Allow doc comment tags such as long @param tags to exceed the 80
54 // character limit. 60 // character limit.
55 return; 61 return;
103 109
104 110
105 /** 111 /**
106 * Returns the length of a defined line. 112 * Returns the length of a defined line.
107 * 113 *
108 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 114 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
109 * @param int $currentLine The current line. 115 * @param int $currentLine The current line.
110 * 116 *
111 * @return int 117 * @return int
112 */ 118 */
113 public function getLineLength(PHP_CodeSniffer_File $phpcsFile, $currentLine) 119 public function getLineLength(File $phpcsFile, $currentLine)
114 { 120 {
115 $tokens = $phpcsFile->getTokens(); 121 $tokens = $phpcsFile->getTokens();
116 122
117 $tokenCount = 0; 123 $tokenCount = 0;
118 $currentLineContent = ''; 124 $currentLineContent = '';