@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function register() |
36 | 36 | { |
37 | - return [T_OPEN_TAG]; |
|
37 | + return [ T_OPEN_TAG ]; |
|
38 | 38 | |
39 | 39 | }//end register() |
40 | 40 | |
@@ -48,29 +48,29 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return int |
50 | 50 | */ |
51 | - public function process(File $phpcsFile, $stackPtr) |
|
51 | + public function process( File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | 53 | // Skip to the end of the file. |
54 | 54 | $tokens = $phpcsFile->getTokens(); |
55 | - $stackPtr = ($phpcsFile->numTokens - 1); |
|
55 | + $stackPtr = ( $phpcsFile->numTokens - 1 ); |
|
56 | 56 | |
57 | - if ($tokens[$stackPtr]['content'] === '') { |
|
57 | + if ( $tokens[ $stackPtr ][ 'content' ] === '' ) { |
|
58 | 58 | --$stackPtr; |
59 | 59 | } |
60 | 60 | |
61 | - $eolCharLen = strlen($phpcsFile->eolChar); |
|
62 | - $lastChars = substr($tokens[$stackPtr]['content'], ($eolCharLen * -1)); |
|
63 | - if ($lastChars === $phpcsFile->eolChar) { |
|
61 | + $eolCharLen = strlen( $phpcsFile->eolChar ); |
|
62 | + $lastChars = substr( $tokens[ $stackPtr ][ 'content' ], ( $eolCharLen * -1 ) ); |
|
63 | + if ( $lastChars === $phpcsFile->eolChar ) { |
|
64 | 64 | $error = 'File must not end with a newline character'; |
65 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found'); |
|
66 | - if ($fix === true) { |
|
65 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Found' ); |
|
66 | + if ( $fix === true ) { |
|
67 | 67 | $phpcsFile->fixer->beginChangeset(); |
68 | 68 | |
69 | - for ($i = $stackPtr; $i > 0; $i--) { |
|
70 | - $newContent = rtrim($tokens[$i]['content'], $phpcsFile->eolChar); |
|
71 | - $phpcsFile->fixer->replaceToken($i, $newContent); |
|
69 | + for ( $i = $stackPtr; $i > 0; $i-- ) { |
|
70 | + $newContent = rtrim( $tokens[ $i ][ 'content' ], $phpcsFile->eolChar ); |
|
71 | + $phpcsFile->fixer->replaceToken( $i, $newContent ); |
|
72 | 72 | |
73 | - if ($newContent !== '') { |
|
73 | + if ( $newContent !== '' ) { |
|
74 | 74 | break; |
75 | 75 | } |
76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | // Ignore the rest of the file. |
83 | - return ($phpcsFile->numTokens + 1); |
|
83 | + return ( $phpcsFile->numTokens + 1 ); |
|
84 | 84 | |
85 | 85 | }//end process() |
86 | 86 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function register() |
36 | 36 | { |
37 | - return [T_OPEN_TAG]; |
|
37 | + return [ T_OPEN_TAG ]; |
|
38 | 38 | |
39 | 39 | }//end register() |
40 | 40 | |
@@ -48,32 +48,32 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return int |
50 | 50 | */ |
51 | - public function process(File $phpcsFile, $stackPtr) |
|
51 | + public function process( File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | 53 | // Skip to the end of the file. |
54 | 54 | $tokens = $phpcsFile->getTokens(); |
55 | - $stackPtr = ($phpcsFile->numTokens - 1); |
|
55 | + $stackPtr = ( $phpcsFile->numTokens - 1 ); |
|
56 | 56 | |
57 | - if ($tokens[$stackPtr]['content'] === '') { |
|
57 | + if ( $tokens[ $stackPtr ][ 'content' ] === '' ) { |
|
58 | 58 | $stackPtr--; |
59 | 59 | } |
60 | 60 | |
61 | - $eolCharLen = strlen($phpcsFile->eolChar); |
|
62 | - $lastChars = substr($tokens[$stackPtr]['content'], ($eolCharLen * -1)); |
|
63 | - if ($lastChars !== $phpcsFile->eolChar) { |
|
64 | - $phpcsFile->recordMetric($stackPtr, 'Newline at EOF', 'no'); |
|
61 | + $eolCharLen = strlen( $phpcsFile->eolChar ); |
|
62 | + $lastChars = substr( $tokens[ $stackPtr ][ 'content' ], ( $eolCharLen * -1 ) ); |
|
63 | + if ( $lastChars !== $phpcsFile->eolChar ) { |
|
64 | + $phpcsFile->recordMetric( $stackPtr, 'Newline at EOF', 'no' ); |
|
65 | 65 | |
66 | 66 | $error = 'File must end with a newline character'; |
67 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotFound'); |
|
68 | - if ($fix === true) { |
|
69 | - $phpcsFile->fixer->addNewline($stackPtr); |
|
67 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'NotFound' ); |
|
68 | + if ( $fix === true ) { |
|
69 | + $phpcsFile->fixer->addNewline( $stackPtr ); |
|
70 | 70 | } |
71 | 71 | } else { |
72 | - $phpcsFile->recordMetric($stackPtr, 'Newline at EOF', 'yes'); |
|
72 | + $phpcsFile->recordMetric( $stackPtr, 'Newline at EOF', 'yes' ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Ignore the rest of the file. |
76 | - return ($phpcsFile->numTokens + 1); |
|
76 | + return ( $phpcsFile->numTokens + 1 ); |
|
77 | 77 | |
78 | 78 | }//end process() |
79 | 79 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function register() |
25 | 25 | { |
26 | - return [T_TRAIT]; |
|
26 | + return [ T_TRAIT ]; |
|
27 | 27 | |
28 | 28 | }//end register() |
29 | 29 | |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - public function process(File $phpcsFile, $stackPtr) |
|
40 | + public function process( File $phpcsFile, $stackPtr ) |
|
41 | 41 | { |
42 | - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); |
|
43 | - if ($nextClass !== false) { |
|
42 | + $nextClass = $phpcsFile->findNext( $this->register(), ( $stackPtr + 1 ) ); |
|
43 | + if ( $nextClass !== false ) { |
|
44 | 44 | $error = 'Only one trait is allowed in a file'; |
45 | - $phpcsFile->addError($error, $nextClass, 'MultipleFound'); |
|
45 | + $phpcsFile->addError( $error, $nextClass, 'MultipleFound' ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | }//end process() |
@@ -68,53 +68,53 @@ |
||
68 | 68 | * |
69 | 69 | * @return void |
70 | 70 | */ |
71 | - public function process(File $phpcsFile, $stackPtr) |
|
71 | + public function process( File $phpcsFile, $stackPtr ) |
|
72 | 72 | { |
73 | 73 | // Work out which type of file this is for. |
74 | 74 | $tokens = $phpcsFile->getTokens(); |
75 | - if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) { |
|
76 | - if ($phpcsFile->tokenizerType === 'JS') { |
|
75 | + if ( $tokens[ $stackPtr ][ 'code' ] === T_STRING_CONCAT ) { |
|
76 | + if ( $phpcsFile->tokenizerType === 'JS' ) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | } else { |
80 | - if ($phpcsFile->tokenizerType === 'PHP') { |
|
80 | + if ( $phpcsFile->tokenizerType === 'PHP' ) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
86 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
87 | - if ($prev === false || $next === false) { |
|
85 | + $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
86 | + $next = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
|
87 | + if ( $prev === false || $next === false ) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - if (isset(Tokens::$stringTokens[$tokens[$prev]['code']]) === true |
|
92 | - && isset(Tokens::$stringTokens[$tokens[$next]['code']]) === true |
|
91 | + if ( isset( Tokens::$stringTokens[ $tokens[ $prev ][ 'code' ] ] ) === true |
|
92 | + && isset( Tokens::$stringTokens[ $tokens[ $next ][ 'code' ] ] ) === true |
|
93 | 93 | ) { |
94 | - if ($tokens[$prev]['content'][0] === $tokens[$next]['content'][0]) { |
|
94 | + if ( $tokens[ $prev ][ 'content' ][ 0 ] === $tokens[ $next ][ 'content' ][ 0 ] ) { |
|
95 | 95 | // Before we throw an error for PHP, allow strings to be |
96 | 96 | // combined if they would have < and ? next to each other because |
97 | 97 | // this trick is sometimes required in PHP strings. |
98 | - if ($phpcsFile->tokenizerType === 'PHP') { |
|
99 | - $prevChar = substr($tokens[$prev]['content'], -2, 1); |
|
100 | - $nextChar = $tokens[$next]['content'][1]; |
|
101 | - $combined = $prevChar.$nextChar; |
|
102 | - if ($combined === '?'.'>' || $combined === '<'.'?') { |
|
98 | + if ( $phpcsFile->tokenizerType === 'PHP' ) { |
|
99 | + $prevChar = substr( $tokens[ $prev ][ 'content' ], -2, 1 ); |
|
100 | + $nextChar = $tokens[ $next ][ 'content' ][ 1 ]; |
|
101 | + $combined = $prevChar . $nextChar; |
|
102 | + if ( $combined === '?' . '>' || $combined === '<' . '?' ) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | - if ($this->allowMultiline === true |
|
108 | - && $tokens[$prev]['line'] !== $tokens[$next]['line'] |
|
107 | + if ( $this->allowMultiline === true |
|
108 | + && $tokens[ $prev ][ 'line' ] !== $tokens[ $next ][ 'line' ] |
|
109 | 109 | ) { |
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $error = 'String concat is not required here; use a single string instead'; |
114 | - if ($this->error === true) { |
|
115 | - $phpcsFile->addError($error, $stackPtr, 'Found'); |
|
114 | + if ( $this->error === true ) { |
|
115 | + $phpcsFile->addError( $error, $stackPtr, 'Found' ); |
|
116 | 116 | } else { |
117 | - $phpcsFile->addWarning($error, $stackPtr, 'Found'); |
|
117 | + $phpcsFile->addWarning( $error, $stackPtr, 'Found' ); |
|
118 | 118 | } |
119 | 119 | }//end if |
120 | 120 | }//end if |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return [T_FUNCTION]; |
|
41 | + return [ T_FUNCTION ]; |
|
42 | 42 | |
43 | 43 | }//end register() |
44 | 44 | |
@@ -52,46 +52,46 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function process(File $phpcsFile, $stackPtr) |
|
55 | + public function process( File $phpcsFile, $stackPtr ) |
|
56 | 56 | { |
57 | 57 | $tokens = $phpcsFile->getTokens(); |
58 | 58 | |
59 | 59 | // Ignore abstract methods. |
60 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
60 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Detect start and end of this function definition. |
65 | - $start = $tokens[$stackPtr]['scope_opener']; |
|
66 | - $end = $tokens[$stackPtr]['scope_closer']; |
|
65 | + $start = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
66 | + $end = $tokens[ $stackPtr ][ 'scope_closer' ]; |
|
67 | 67 | |
68 | 68 | $nestingLevel = 0; |
69 | 69 | |
70 | 70 | // Find the maximum nesting level of any token in the function. |
71 | - for ($i = ($start + 1); $i < $end; $i++) { |
|
72 | - $level = $tokens[$i]['level']; |
|
73 | - if ($nestingLevel < $level) { |
|
71 | + for ( $i = ( $start + 1 ); $i < $end; $i++ ) { |
|
72 | + $level = $tokens[ $i ][ 'level' ]; |
|
73 | + if ( $nestingLevel < $level ) { |
|
74 | 74 | $nestingLevel = $level; |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | 78 | // We subtract the nesting level of the function itself. |
79 | - $nestingLevel = ($nestingLevel - $tokens[$stackPtr]['level'] - 1); |
|
79 | + $nestingLevel = ( $nestingLevel - $tokens[ $stackPtr ][ 'level' ] - 1 ); |
|
80 | 80 | |
81 | - if ($nestingLevel > $this->absoluteNestingLevel) { |
|
81 | + if ( $nestingLevel > $this->absoluteNestingLevel ) { |
|
82 | 82 | $error = 'Function\'s nesting level (%s) exceeds allowed maximum of %s'; |
83 | 83 | $data = [ |
84 | 84 | $nestingLevel, |
85 | 85 | $this->absoluteNestingLevel, |
86 | 86 | ]; |
87 | - $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data); |
|
88 | - } else if ($nestingLevel > $this->nestingLevel) { |
|
87 | + $phpcsFile->addError( $error, $stackPtr, 'MaxExceeded', $data ); |
|
88 | + } else if ( $nestingLevel > $this->nestingLevel ) { |
|
89 | 89 | $warning = 'Function\'s nesting level (%s) exceeds %s; consider refactoring the function'; |
90 | 90 | $data = [ |
91 | 91 | $nestingLevel, |
92 | 92 | $this->nestingLevel, |
93 | 93 | ]; |
94 | - $phpcsFile->addWarning($warning, $stackPtr, 'TooHigh', $data); |
|
94 | + $phpcsFile->addWarning( $warning, $stackPtr, 'TooHigh', $data ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | }//end process() |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function register() |
44 | 44 | { |
45 | - return [T_FUNCTION]; |
|
45 | + return [ T_FUNCTION ]; |
|
46 | 46 | |
47 | 47 | }//end register() |
48 | 48 | |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return void |
58 | 58 | */ |
59 | - public function process(File $phpcsFile, $stackPtr) |
|
59 | + public function process( File $phpcsFile, $stackPtr ) |
|
60 | 60 | { |
61 | 61 | $tokens = $phpcsFile->getTokens(); |
62 | 62 | |
63 | 63 | // Ignore abstract methods. |
64 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
64 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Detect start and end of this function definition. |
69 | - $start = $tokens[$stackPtr]['scope_opener']; |
|
70 | - $end = $tokens[$stackPtr]['scope_closer']; |
|
69 | + $start = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
70 | + $end = $tokens[ $stackPtr ][ 'scope_closer' ]; |
|
71 | 71 | |
72 | 72 | // Predicate nodes for PHP. |
73 | 73 | $find = [ |
@@ -85,26 +85,26 @@ discard block |
||
85 | 85 | $complexity = 1; |
86 | 86 | |
87 | 87 | // Iterate from start to end and count predicate nodes. |
88 | - for ($i = ($start + 1); $i < $end; $i++) { |
|
89 | - if (isset($find[$tokens[$i]['code']]) === true) { |
|
88 | + for ( $i = ( $start + 1 ); $i < $end; $i++ ) { |
|
89 | + if ( isset( $find[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
90 | 90 | $complexity++; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - if ($complexity > $this->absoluteComplexity) { |
|
94 | + if ( $complexity > $this->absoluteComplexity ) { |
|
95 | 95 | $error = 'Function\'s cyclomatic complexity (%s) exceeds allowed maximum of %s'; |
96 | 96 | $data = [ |
97 | 97 | $complexity, |
98 | 98 | $this->absoluteComplexity, |
99 | 99 | ]; |
100 | - $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data); |
|
101 | - } else if ($complexity > $this->complexity) { |
|
100 | + $phpcsFile->addError( $error, $stackPtr, 'MaxExceeded', $data ); |
|
101 | + } else if ( $complexity > $this->complexity ) { |
|
102 | 102 | $warning = 'Function\'s cyclomatic complexity (%s) exceeds %s; consider refactoring the function'; |
103 | 103 | $data = [ |
104 | 104 | $complexity, |
105 | 105 | $this->complexity, |
106 | 106 | ]; |
107 | - $phpcsFile->addWarning($warning, $stackPtr, 'TooHigh', $data); |
|
107 | + $phpcsFile->addWarning( $warning, $stackPtr, 'TooHigh', $data ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | }//end process() |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function register() |
35 | 35 | { |
36 | - return [T_DOC_COMMENT_OPEN_TAG]; |
|
36 | + return [ T_DOC_COMMENT_OPEN_TAG ]; |
|
37 | 37 | |
38 | 38 | }//end register() |
39 | 39 | |
@@ -47,68 +47,68 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public function process(File $phpcsFile, $stackPtr) |
|
50 | + public function process( File $phpcsFile, $stackPtr ) |
|
51 | 51 | { |
52 | 52 | $tokens = $phpcsFile->getTokens(); |
53 | 53 | |
54 | - if (isset($tokens[$stackPtr]['comment_closer']) === false |
|
55 | - || ($tokens[$tokens[$stackPtr]['comment_closer']]['content'] === '' |
|
56 | - && $tokens[$stackPtr]['comment_closer'] === ($phpcsFile->numTokens - 1)) |
|
54 | + if ( isset( $tokens[ $stackPtr ][ 'comment_closer' ] ) === false |
|
55 | + || ( $tokens[ $tokens[ $stackPtr ][ 'comment_closer' ] ][ 'content' ] === '' |
|
56 | + && $tokens[ $stackPtr ][ 'comment_closer' ] === ( $phpcsFile->numTokens - 1 ) ) |
|
57 | 57 | ) { |
58 | 58 | // Don't process an unfinished comment during live coding. |
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | 62 | $commentStart = $stackPtr; |
63 | - $commentEnd = $tokens[$stackPtr]['comment_closer']; |
|
63 | + $commentEnd = $tokens[ $stackPtr ][ 'comment_closer' ]; |
|
64 | 64 | |
65 | 65 | $empty = [ |
66 | 66 | T_DOC_COMMENT_WHITESPACE, |
67 | 67 | T_DOC_COMMENT_STAR, |
68 | 68 | ]; |
69 | 69 | |
70 | - $short = $phpcsFile->findNext($empty, ($stackPtr + 1), $commentEnd, true); |
|
71 | - if ($short === false) { |
|
70 | + $short = $phpcsFile->findNext( $empty, ( $stackPtr + 1 ), $commentEnd, true ); |
|
71 | + if ( $short === false ) { |
|
72 | 72 | // No content at all. |
73 | 73 | $error = 'Doc comment is empty'; |
74 | - $phpcsFile->addError($error, $stackPtr, 'Empty'); |
|
74 | + $phpcsFile->addError( $error, $stackPtr, 'Empty' ); |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | 78 | // The first line of the comment should just be the /** code. |
79 | - if ($tokens[$short]['line'] === $tokens[$stackPtr]['line']) { |
|
79 | + if ( $tokens[ $short ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) { |
|
80 | 80 | $error = 'The open comment tag must be the only content on the line'; |
81 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen'); |
|
82 | - if ($fix === true) { |
|
81 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'ContentAfterOpen' ); |
|
82 | + if ( $fix === true ) { |
|
83 | 83 | $phpcsFile->fixer->beginChangeset(); |
84 | - $phpcsFile->fixer->addNewline($stackPtr); |
|
85 | - $phpcsFile->fixer->addContentBefore($short, '* '); |
|
84 | + $phpcsFile->fixer->addNewline( $stackPtr ); |
|
85 | + $phpcsFile->fixer->addContentBefore( $short, '* ' ); |
|
86 | 86 | $phpcsFile->fixer->endChangeset(); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | 90 | // The last line of the comment should just be the */ code. |
91 | - $prev = $phpcsFile->findPrevious($empty, ($commentEnd - 1), $stackPtr, true); |
|
92 | - if ($tokens[$prev]['line'] === $tokens[$commentEnd]['line']) { |
|
91 | + $prev = $phpcsFile->findPrevious( $empty, ( $commentEnd - 1 ), $stackPtr, true ); |
|
92 | + if ( $tokens[ $prev ][ 'line' ] === $tokens[ $commentEnd ][ 'line' ] ) { |
|
93 | 93 | $error = 'The close comment tag must be the only content on the line'; |
94 | - $fix = $phpcsFile->addFixableError($error, $commentEnd, 'ContentBeforeClose'); |
|
95 | - if ($fix === true) { |
|
96 | - $phpcsFile->fixer->addNewlineBefore($commentEnd); |
|
94 | + $fix = $phpcsFile->addFixableError( $error, $commentEnd, 'ContentBeforeClose' ); |
|
95 | + if ( $fix === true ) { |
|
96 | + $phpcsFile->fixer->addNewlineBefore( $commentEnd ); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | 100 | // Check for additional blank lines at the end of the comment. |
101 | - if ($tokens[$prev]['line'] < ($tokens[$commentEnd]['line'] - 1)) { |
|
101 | + if ( $tokens[ $prev ][ 'line' ] < ( $tokens[ $commentEnd ][ 'line' ] - 1 ) ) { |
|
102 | 102 | $error = 'Additional blank lines found at end of doc comment'; |
103 | - $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter'); |
|
104 | - if ($fix === true) { |
|
103 | + $fix = $phpcsFile->addFixableError( $error, $commentEnd, 'SpacingAfter' ); |
|
104 | + if ( $fix === true ) { |
|
105 | 105 | $phpcsFile->fixer->beginChangeset(); |
106 | - for ($i = ($prev + 1); $i < $commentEnd; $i++) { |
|
107 | - if ($tokens[($i + 1)]['line'] === $tokens[$commentEnd]['line']) { |
|
106 | + for ( $i = ( $prev + 1 ); $i < $commentEnd; $i++ ) { |
|
107 | + if ( $tokens[ ( $i + 1 ) ][ 'line' ] === $tokens[ $commentEnd ][ 'line' ] ) { |
|
108 | 108 | break; |
109 | 109 | } |
110 | 110 | |
111 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
111 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $phpcsFile->fixer->endChangeset(); |
@@ -116,24 +116,24 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | // Check for a comment description. |
119 | - if ($tokens[$short]['code'] !== T_DOC_COMMENT_STRING) { |
|
119 | + if ( $tokens[ $short ][ 'code' ] !== T_DOC_COMMENT_STRING ) { |
|
120 | 120 | $error = 'Missing short description in doc comment'; |
121 | - $phpcsFile->addError($error, $stackPtr, 'MissingShort'); |
|
121 | + $phpcsFile->addError( $error, $stackPtr, 'MissingShort' ); |
|
122 | 122 | } else { |
123 | 123 | // No extra newline before short description. |
124 | - if ($tokens[$short]['line'] !== ($tokens[$stackPtr]['line'] + 1)) { |
|
124 | + if ( $tokens[ $short ][ 'line' ] !== ( $tokens[ $stackPtr ][ 'line' ] + 1 ) ) { |
|
125 | 125 | $error = 'Doc comment short description must be on the first line'; |
126 | - $fix = $phpcsFile->addFixableError($error, $short, 'SpacingBeforeShort'); |
|
127 | - if ($fix === true) { |
|
126 | + $fix = $phpcsFile->addFixableError( $error, $short, 'SpacingBeforeShort' ); |
|
127 | + if ( $fix === true ) { |
|
128 | 128 | $phpcsFile->fixer->beginChangeset(); |
129 | - for ($i = $stackPtr; $i < $short; $i++) { |
|
130 | - if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { |
|
129 | + for ( $i = $stackPtr; $i < $short; $i++ ) { |
|
130 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) { |
|
131 | 131 | continue; |
132 | - } else if ($tokens[$i]['line'] === $tokens[$short]['line']) { |
|
132 | + } else if ( $tokens[ $i ][ 'line' ] === $tokens[ $short ][ 'line' ] ) { |
|
133 | 133 | break; |
134 | 134 | } |
135 | 135 | |
136 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
136 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $phpcsFile->fixer->endChangeset(); |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | |
143 | 143 | // Account for the fact that a short description might cover |
144 | 144 | // multiple lines. |
145 | - $shortContent = $tokens[$short]['content']; |
|
145 | + $shortContent = $tokens[ $short ][ 'content' ]; |
|
146 | 146 | $shortEnd = $short; |
147 | - for ($i = ($short + 1); $i < $commentEnd; $i++) { |
|
148 | - if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { |
|
149 | - if ($tokens[$i]['line'] === ($tokens[$shortEnd]['line'] + 1)) { |
|
150 | - $shortContent .= $tokens[$i]['content']; |
|
147 | + for ( $i = ( $short + 1 ); $i < $commentEnd; $i++ ) { |
|
148 | + if ( $tokens[ $i ][ 'code' ] === T_DOC_COMMENT_STRING ) { |
|
149 | + if ( $tokens[ $i ][ 'line' ] === ( $tokens[ $shortEnd ][ 'line' ] + 1 ) ) { |
|
150 | + $shortContent .= $tokens[ $i ][ 'content' ]; |
|
151 | 151 | $shortEnd = $i; |
152 | 152 | } else { |
153 | 153 | break; |
@@ -155,63 +155,63 @@ discard block |
||
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | - if (preg_match('/^\p{Ll}/u', $shortContent) === 1) { |
|
158 | + if ( preg_match( '/^\p{Ll}/u', $shortContent ) === 1 ) { |
|
159 | 159 | $error = 'Doc comment short description must start with a capital letter'; |
160 | - $phpcsFile->addError($error, $short, 'ShortNotCapital'); |
|
160 | + $phpcsFile->addError( $error, $short, 'ShortNotCapital' ); |
|
161 | 161 | } |
162 | 162 | |
163 | - $long = $phpcsFile->findNext($empty, ($shortEnd + 1), ($commentEnd - 1), true); |
|
164 | - if ($long !== false && $tokens[$long]['code'] === T_DOC_COMMENT_STRING) { |
|
165 | - if ($tokens[$long]['line'] !== ($tokens[$shortEnd]['line'] + 2)) { |
|
163 | + $long = $phpcsFile->findNext( $empty, ( $shortEnd + 1 ), ( $commentEnd - 1 ), true ); |
|
164 | + if ( $long !== false && $tokens[ $long ][ 'code' ] === T_DOC_COMMENT_STRING ) { |
|
165 | + if ( $tokens[ $long ][ 'line' ] !== ( $tokens[ $shortEnd ][ 'line' ] + 2 ) ) { |
|
166 | 166 | $error = 'There must be exactly one blank line between descriptions in a doc comment'; |
167 | - $fix = $phpcsFile->addFixableError($error, $long, 'SpacingBetween'); |
|
168 | - if ($fix === true) { |
|
167 | + $fix = $phpcsFile->addFixableError( $error, $long, 'SpacingBetween' ); |
|
168 | + if ( $fix === true ) { |
|
169 | 169 | $phpcsFile->fixer->beginChangeset(); |
170 | - for ($i = ($shortEnd + 1); $i < $long; $i++) { |
|
171 | - if ($tokens[$i]['line'] === $tokens[$shortEnd]['line']) { |
|
170 | + for ( $i = ( $shortEnd + 1 ); $i < $long; $i++ ) { |
|
171 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $shortEnd ][ 'line' ] ) { |
|
172 | 172 | continue; |
173 | - } else if ($tokens[$i]['line'] === ($tokens[$long]['line'] - 1)) { |
|
173 | + } else if ( $tokens[ $i ][ 'line' ] === ( $tokens[ $long ][ 'line' ] - 1 ) ) { |
|
174 | 174 | break; |
175 | 175 | } |
176 | 176 | |
177 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
177 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $phpcsFile->fixer->endChangeset(); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - if (preg_match('/^\p{Ll}/u', $tokens[$long]['content']) === 1) { |
|
184 | + if ( preg_match( '/^\p{Ll}/u', $tokens[ $long ][ 'content' ] ) === 1 ) { |
|
185 | 185 | $error = 'Doc comment long description must start with a capital letter'; |
186 | - $phpcsFile->addError($error, $long, 'LongNotCapital'); |
|
186 | + $phpcsFile->addError( $error, $long, 'LongNotCapital' ); |
|
187 | 187 | } |
188 | 188 | }//end if |
189 | 189 | }//end if |
190 | 190 | |
191 | - if (empty($tokens[$commentStart]['comment_tags']) === true) { |
|
191 | + if ( empty( $tokens[ $commentStart ][ 'comment_tags' ] ) === true ) { |
|
192 | 192 | // No tags in the comment. |
193 | 193 | return; |
194 | 194 | } |
195 | 195 | |
196 | - $firstTag = $tokens[$commentStart]['comment_tags'][0]; |
|
197 | - $prev = $phpcsFile->findPrevious($empty, ($firstTag - 1), $stackPtr, true); |
|
198 | - if ($tokens[$firstTag]['line'] !== ($tokens[$prev]['line'] + 2) |
|
199 | - && $tokens[$prev]['code'] !== T_DOC_COMMENT_OPEN_TAG |
|
196 | + $firstTag = $tokens[ $commentStart ][ 'comment_tags' ][ 0 ]; |
|
197 | + $prev = $phpcsFile->findPrevious( $empty, ( $firstTag - 1 ), $stackPtr, true ); |
|
198 | + if ( $tokens[ $firstTag ][ 'line' ] !== ( $tokens[ $prev ][ 'line' ] + 2 ) |
|
199 | + && $tokens[ $prev ][ 'code' ] !== T_DOC_COMMENT_OPEN_TAG |
|
200 | 200 | ) { |
201 | 201 | $error = 'There must be exactly one blank line before the tags in a doc comment'; |
202 | - $fix = $phpcsFile->addFixableError($error, $firstTag, 'SpacingBeforeTags'); |
|
203 | - if ($fix === true) { |
|
202 | + $fix = $phpcsFile->addFixableError( $error, $firstTag, 'SpacingBeforeTags' ); |
|
203 | + if ( $fix === true ) { |
|
204 | 204 | $phpcsFile->fixer->beginChangeset(); |
205 | - for ($i = ($prev + 1); $i < $firstTag; $i++) { |
|
206 | - if ($tokens[$i]['line'] === $tokens[$firstTag]['line']) { |
|
205 | + for ( $i = ( $prev + 1 ); $i < $firstTag; $i++ ) { |
|
206 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $firstTag ][ 'line' ] ) { |
|
207 | 207 | break; |
208 | 208 | } |
209 | 209 | |
210 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
210 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
211 | 211 | } |
212 | 212 | |
213 | - $indent = str_repeat(' ', $tokens[$stackPtr]['column']); |
|
214 | - $phpcsFile->fixer->addContent($prev, $phpcsFile->eolChar.$indent.'*'.$phpcsFile->eolChar); |
|
213 | + $indent = str_repeat( ' ', $tokens[ $stackPtr ][ 'column' ] ); |
|
214 | + $phpcsFile->fixer->addContent( $prev, $phpcsFile->eolChar . $indent . '*' . $phpcsFile->eolChar ); |
|
215 | 215 | $phpcsFile->fixer->endChangeset(); |
216 | 216 | } |
217 | 217 | } |
@@ -219,132 +219,132 @@ discard block |
||
219 | 219 | // Break out the tags into groups and check alignment within each. |
220 | 220 | // A tag group is one where there are no blank lines between tags. |
221 | 221 | // The param tag group is special as it requires all @param tags to be inside. |
222 | - $tagGroups = []; |
|
222 | + $tagGroups = [ ]; |
|
223 | 223 | $groupid = 0; |
224 | 224 | $paramGroupid = null; |
225 | - foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) { |
|
226 | - if ($pos > 0) { |
|
225 | + foreach ( $tokens[ $commentStart ][ 'comment_tags' ] as $pos => $tag ) { |
|
226 | + if ( $pos > 0 ) { |
|
227 | 227 | $prev = $phpcsFile->findPrevious( |
228 | 228 | T_DOC_COMMENT_STRING, |
229 | - ($tag - 1), |
|
230 | - $tokens[$commentStart]['comment_tags'][($pos - 1)] |
|
229 | + ( $tag - 1 ), |
|
230 | + $tokens[ $commentStart ][ 'comment_tags' ][ ( $pos - 1 ) ] |
|
231 | 231 | ); |
232 | 232 | |
233 | - if ($prev === false) { |
|
234 | - $prev = $tokens[$commentStart]['comment_tags'][($pos - 1)]; |
|
233 | + if ( $prev === false ) { |
|
234 | + $prev = $tokens[ $commentStart ][ 'comment_tags' ][ ( $pos - 1 ) ]; |
|
235 | 235 | } |
236 | 236 | |
237 | - if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 1)) { |
|
237 | + if ( $tokens[ $prev ][ 'line' ] !== ( $tokens[ $tag ][ 'line' ] - 1 ) ) { |
|
238 | 238 | $groupid++; |
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | - if ($tokens[$tag]['content'] === '@param') { |
|
243 | - if ($paramGroupid !== null |
|
242 | + if ( $tokens[ $tag ][ 'content' ] === '@param' ) { |
|
243 | + if ( $paramGroupid !== null |
|
244 | 244 | && $paramGroupid !== $groupid |
245 | 245 | ) { |
246 | 246 | $error = 'Parameter tags must be grouped together in a doc comment'; |
247 | - $phpcsFile->addError($error, $tag, 'ParamGroup'); |
|
247 | + $phpcsFile->addError( $error, $tag, 'ParamGroup' ); |
|
248 | 248 | } |
249 | 249 | |
250 | - if ($paramGroupid === null) { |
|
250 | + if ( $paramGroupid === null ) { |
|
251 | 251 | $paramGroupid = $groupid; |
252 | 252 | } |
253 | 253 | }//end if |
254 | 254 | |
255 | - $tagGroups[$groupid][] = $tag; |
|
255 | + $tagGroups[ $groupid ][ ] = $tag; |
|
256 | 256 | }//end foreach |
257 | 257 | |
258 | - foreach ($tagGroups as $groupid => $group) { |
|
258 | + foreach ( $tagGroups as $groupid => $group ) { |
|
259 | 259 | $maxLength = 0; |
260 | - $paddings = []; |
|
261 | - foreach ($group as $pos => $tag) { |
|
262 | - if ($paramGroupid === $groupid |
|
263 | - && $tokens[$tag]['content'] !== '@param' |
|
260 | + $paddings = [ ]; |
|
261 | + foreach ( $group as $pos => $tag ) { |
|
262 | + if ( $paramGroupid === $groupid |
|
263 | + && $tokens[ $tag ][ 'content' ] !== '@param' |
|
264 | 264 | ) { |
265 | 265 | $error = 'Tag %s cannot be grouped with parameter tags in a doc comment'; |
266 | - $data = [$tokens[$tag]['content']]; |
|
267 | - $phpcsFile->addError($error, $tag, 'NonParamGroup', $data); |
|
266 | + $data = [ $tokens[ $tag ][ 'content' ] ]; |
|
267 | + $phpcsFile->addError( $error, $tag, 'NonParamGroup', $data ); |
|
268 | 268 | } |
269 | 269 | |
270 | - $tagLength = $tokens[$tag]['length']; |
|
271 | - if ($tagLength > $maxLength) { |
|
270 | + $tagLength = $tokens[ $tag ][ 'length' ]; |
|
271 | + if ( $tagLength > $maxLength ) { |
|
272 | 272 | $maxLength = $tagLength; |
273 | 273 | } |
274 | 274 | |
275 | 275 | // Check for a value. No value means no padding needed. |
276 | - $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd); |
|
277 | - if ($string !== false && $tokens[$string]['line'] === $tokens[$tag]['line']) { |
|
278 | - $paddings[$tag] = $tokens[($tag + 1)]['length']; |
|
276 | + $string = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $tag, $commentEnd ); |
|
277 | + if ( $string !== false && $tokens[ $string ][ 'line' ] === $tokens[ $tag ][ 'line' ] ) { |
|
278 | + $paddings[ $tag ] = $tokens[ ( $tag + 1 ) ][ 'length' ]; |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Check that there was single blank line after the tag block |
283 | 283 | // but account for a multi-line tag comments. |
284 | - $lastTag = $group[$pos]; |
|
285 | - $next = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($lastTag + 3), $commentEnd); |
|
286 | - if ($next !== false) { |
|
287 | - $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING], ($next - 1), $commentStart); |
|
288 | - if ($tokens[$next]['line'] !== ($tokens[$prev]['line'] + 2)) { |
|
284 | + $lastTag = $group[ $pos ]; |
|
285 | + $next = $phpcsFile->findNext( T_DOC_COMMENT_TAG, ( $lastTag + 3 ), $commentEnd ); |
|
286 | + if ( $next !== false ) { |
|
287 | + $prev = $phpcsFile->findPrevious( [ T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING ], ( $next - 1 ), $commentStart ); |
|
288 | + if ( $tokens[ $next ][ 'line' ] !== ( $tokens[ $prev ][ 'line' ] + 2 ) ) { |
|
289 | 289 | $error = 'There must be a single blank line after a tag group'; |
290 | - $fix = $phpcsFile->addFixableError($error, $lastTag, 'SpacingAfterTagGroup'); |
|
291 | - if ($fix === true) { |
|
290 | + $fix = $phpcsFile->addFixableError( $error, $lastTag, 'SpacingAfterTagGroup' ); |
|
291 | + if ( $fix === true ) { |
|
292 | 292 | $phpcsFile->fixer->beginChangeset(); |
293 | - for ($i = ($prev + 1); $i < $next; $i++) { |
|
294 | - if ($tokens[$i]['line'] === $tokens[$next]['line']) { |
|
293 | + for ( $i = ( $prev + 1 ); $i < $next; $i++ ) { |
|
294 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $next ][ 'line' ] ) { |
|
295 | 295 | break; |
296 | 296 | } |
297 | 297 | |
298 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
298 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
299 | 299 | } |
300 | 300 | |
301 | - $indent = str_repeat(' ', $tokens[$stackPtr]['column']); |
|
302 | - $phpcsFile->fixer->addContent($prev, $phpcsFile->eolChar.$indent.'*'.$phpcsFile->eolChar); |
|
301 | + $indent = str_repeat( ' ', $tokens[ $stackPtr ][ 'column' ] ); |
|
302 | + $phpcsFile->fixer->addContent( $prev, $phpcsFile->eolChar . $indent . '*' . $phpcsFile->eolChar ); |
|
303 | 303 | $phpcsFile->fixer->endChangeset(); |
304 | 304 | } |
305 | 305 | } |
306 | 306 | }//end if |
307 | 307 | |
308 | 308 | // Now check paddings. |
309 | - foreach ($paddings as $tag => $padding) { |
|
310 | - $required = ($maxLength - $tokens[$tag]['length'] + 1); |
|
309 | + foreach ( $paddings as $tag => $padding ) { |
|
310 | + $required = ( $maxLength - $tokens[ $tag ][ 'length' ] + 1 ); |
|
311 | 311 | |
312 | - if ($padding !== $required) { |
|
312 | + if ( $padding !== $required ) { |
|
313 | 313 | $error = 'Tag value for %s tag indented incorrectly; expected %s spaces but found %s'; |
314 | 314 | $data = [ |
315 | - $tokens[$tag]['content'], |
|
315 | + $tokens[ $tag ][ 'content' ], |
|
316 | 316 | $required, |
317 | 317 | $padding, |
318 | 318 | ]; |
319 | 319 | |
320 | - $fix = $phpcsFile->addFixableError($error, ($tag + 1), 'TagValueIndent', $data); |
|
321 | - if ($fix === true) { |
|
322 | - $phpcsFile->fixer->replaceToken(($tag + 1), str_repeat(' ', $required)); |
|
320 | + $fix = $phpcsFile->addFixableError( $error, ( $tag + 1 ), 'TagValueIndent', $data ); |
|
321 | + if ( $fix === true ) { |
|
322 | + $phpcsFile->fixer->replaceToken( ( $tag + 1 ), str_repeat( ' ', $required ) ); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
326 | 326 | }//end foreach |
327 | 327 | |
328 | 328 | // If there is a param group, it needs to be first. |
329 | - if ($paramGroupid !== null && $paramGroupid !== 0) { |
|
329 | + if ( $paramGroupid !== null && $paramGroupid !== 0 ) { |
|
330 | 330 | $error = 'Parameter tags must be defined first in a doc comment'; |
331 | - $phpcsFile->addError($error, $tagGroups[$paramGroupid][0], 'ParamNotFirst'); |
|
331 | + $phpcsFile->addError( $error, $tagGroups[ $paramGroupid ][ 0 ], 'ParamNotFirst' ); |
|
332 | 332 | } |
333 | 333 | |
334 | - $foundTags = []; |
|
335 | - foreach ($tokens[$stackPtr]['comment_tags'] as $pos => $tag) { |
|
336 | - $tagName = $tokens[$tag]['content']; |
|
337 | - if (isset($foundTags[$tagName]) === true) { |
|
338 | - $lastTag = $tokens[$stackPtr]['comment_tags'][($pos - 1)]; |
|
339 | - if ($tokens[$lastTag]['content'] !== $tagName) { |
|
334 | + $foundTags = [ ]; |
|
335 | + foreach ( $tokens[ $stackPtr ][ 'comment_tags' ] as $pos => $tag ) { |
|
336 | + $tagName = $tokens[ $tag ][ 'content' ]; |
|
337 | + if ( isset( $foundTags[ $tagName ] ) === true ) { |
|
338 | + $lastTag = $tokens[ $stackPtr ][ 'comment_tags' ][ ( $pos - 1 ) ]; |
|
339 | + if ( $tokens[ $lastTag ][ 'content' ] !== $tagName ) { |
|
340 | 340 | $error = 'Tags must be grouped together in a doc comment'; |
341 | - $phpcsFile->addError($error, $tag, 'TagsNotGrouped'); |
|
341 | + $phpcsFile->addError( $error, $tag, 'TagsNotGrouped' ); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | continue; |
345 | 345 | } |
346 | 346 | |
347 | - $foundTags[$tagName] = true; |
|
347 | + $foundTags[ $tagName ] = true; |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | }//end process() |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function register() |
37 | 37 | { |
38 | - return array_diff(Tokens::$commentTokens, Tokens::$phpcsCommentTokens); |
|
38 | + return array_diff( Tokens::$commentTokens, Tokens::$phpcsCommentTokens ); |
|
39 | 39 | |
40 | 40 | }//end register() |
41 | 41 | |
@@ -49,27 +49,27 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return void |
51 | 51 | */ |
52 | - public function process(File $phpcsFile, $stackPtr) |
|
52 | + public function process( File $phpcsFile, $stackPtr ) |
|
53 | 53 | { |
54 | 54 | $tokens = $phpcsFile->getTokens(); |
55 | 55 | |
56 | - $content = $tokens[$stackPtr]['content']; |
|
57 | - $matches = []; |
|
58 | - preg_match('/(?:\A|[^\p{L}]+)fixme([^\p{L}]+(.*)|\Z)/ui', $content, $matches); |
|
59 | - if (empty($matches) === false) { |
|
56 | + $content = $tokens[ $stackPtr ][ 'content' ]; |
|
57 | + $matches = [ ]; |
|
58 | + preg_match( '/(?:\A|[^\p{L}]+)fixme([^\p{L}]+(.*)|\Z)/ui', $content, $matches ); |
|
59 | + if ( empty( $matches ) === false ) { |
|
60 | 60 | // Clear whitespace and some common characters not required at |
61 | 61 | // the end of a fixme message to make the error more informative. |
62 | 62 | $type = 'CommentFound'; |
63 | - $fixmeMessage = trim($matches[1]); |
|
64 | - $fixmeMessage = trim($fixmeMessage, '-:[](). '); |
|
63 | + $fixmeMessage = trim( $matches[ 1 ] ); |
|
64 | + $fixmeMessage = trim( $fixmeMessage, '-:[](). ' ); |
|
65 | 65 | $error = 'Comment refers to a FIXME task'; |
66 | - $data = [$fixmeMessage]; |
|
67 | - if ($fixmeMessage !== '') { |
|
66 | + $data = [ $fixmeMessage ]; |
|
67 | + if ( $fixmeMessage !== '' ) { |
|
68 | 68 | $type = 'TaskFound'; |
69 | 69 | $error .= ' "%s"'; |
70 | 70 | } |
71 | 71 | |
72 | - $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
72 | + $phpcsFile->addError( $error, $stackPtr, $type, $data ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | }//end process() |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function register() |
36 | 36 | { |
37 | - return array_diff(Tokens::$commentTokens, Tokens::$phpcsCommentTokens); |
|
37 | + return array_diff( Tokens::$commentTokens, Tokens::$phpcsCommentTokens ); |
|
38 | 38 | |
39 | 39 | }//end register() |
40 | 40 | |
@@ -48,27 +48,27 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - public function process(File $phpcsFile, $stackPtr) |
|
51 | + public function process( File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | 53 | $tokens = $phpcsFile->getTokens(); |
54 | 54 | |
55 | - $content = $tokens[$stackPtr]['content']; |
|
56 | - $matches = []; |
|
57 | - preg_match('/(?:\A|[^\p{L}]+)todo([^\p{L}]+(.*)|\Z)/ui', $content, $matches); |
|
58 | - if (empty($matches) === false) { |
|
55 | + $content = $tokens[ $stackPtr ][ 'content' ]; |
|
56 | + $matches = [ ]; |
|
57 | + preg_match( '/(?:\A|[^\p{L}]+)todo([^\p{L}]+(.*)|\Z)/ui', $content, $matches ); |
|
58 | + if ( empty( $matches ) === false ) { |
|
59 | 59 | // Clear whitespace and some common characters not required at |
60 | 60 | // the end of a to-do message to make the warning more informative. |
61 | 61 | $type = 'CommentFound'; |
62 | - $todoMessage = trim($matches[1]); |
|
63 | - $todoMessage = trim($todoMessage, '-:[](). '); |
|
62 | + $todoMessage = trim( $matches[ 1 ] ); |
|
63 | + $todoMessage = trim( $todoMessage, '-:[](). ' ); |
|
64 | 64 | $error = 'Comment refers to a TODO task'; |
65 | - $data = [$todoMessage]; |
|
66 | - if ($todoMessage !== '') { |
|
65 | + $data = [ $todoMessage ]; |
|
66 | + if ( $todoMessage !== '' ) { |
|
67 | 67 | $type = 'TaskFound'; |
68 | 68 | $error .= ' "%s"'; |
69 | 69 | } |
70 | 70 | |
71 | - $phpcsFile->addWarning($error, $stackPtr, $type, $data); |
|
71 | + $phpcsFile->addWarning( $error, $stackPtr, $type, $data ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | }//end process() |