@@ -18,18 +18,18 @@ discard block |
||
18 | 18 | * @inheritDoc |
19 | 19 | */ |
20 | 20 | public function __construct() { |
21 | - parent::__construct([T_CLASS], [T_FUNCTION]); |
|
21 | + parent::__construct( [ T_CLASS ], [ T_FUNCTION ] ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @inheritDoc |
26 | 26 | */ |
27 | - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) { |
|
27 | + protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope ) { |
|
28 | 28 | $tokens = $phpcsFile->getTokens(); |
29 | 29 | |
30 | 30 | // Type of method |
31 | - $method = $phpcsFile->findNext(T_STRING, ($stackPtr + 1)); |
|
32 | - $returnRequired = !in_array($tokens[$method]['content'], ['__construct', '__destruct']); |
|
31 | + $method = $phpcsFile->findNext( T_STRING, ( $stackPtr + 1 ) ); |
|
32 | + $returnRequired = ! in_array( $tokens[ $method ][ 'content' ], [ '__construct', '__destruct' ] ); |
|
33 | 33 | |
34 | 34 | $find = [ |
35 | 35 | T_COMMENT, |
@@ -39,49 +39,49 @@ discard block |
||
39 | 39 | T_OPEN_TAG, |
40 | 40 | ]; |
41 | 41 | |
42 | - $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1)); |
|
42 | + $commentEnd = $phpcsFile->findPrevious( $find, ( $stackPtr - 1 ) ); |
|
43 | 43 | |
44 | - if ($commentEnd === false) { |
|
44 | + if ( $commentEnd === false ) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT) { |
|
48 | + if ( $tokens[ $commentEnd ][ 'code' ] !== T_DOC_COMMENT ) { |
|
49 | 49 | // Function doesn't have a comment. Let someone else warn about that. |
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - $commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1); |
|
53 | + $commentStart = ( $phpcsFile->findPrevious( T_DOC_COMMENT, ( $commentEnd - 1 ), null, true ) + 1 ); |
|
54 | 54 | |
55 | 55 | $commentWithReturn = null; |
56 | - for ($i = $commentEnd; $i >= $commentStart; $i--) { |
|
57 | - $currentComment = $tokens[$i]['content']; |
|
58 | - if (strpos($currentComment, '@return ') !== false) { |
|
56 | + for ( $i = $commentEnd; $i >= $commentStart; $i-- ) { |
|
57 | + $currentComment = $tokens[ $i ][ 'content' ]; |
|
58 | + if ( strpos( $currentComment, '@return ' ) !== false ) { |
|
59 | 59 | $commentWithReturn = $i; |
60 | 60 | break; |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - if (!$commentWithReturn && !$returnRequired) { |
|
64 | + if ( ! $commentWithReturn && ! $returnRequired ) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - if ($commentWithReturn && $returnRequired) { |
|
68 | + if ( $commentWithReturn && $returnRequired ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // A class method should have @return |
73 | - if (!$commentWithReturn) { |
|
73 | + if ( ! $commentWithReturn ) { |
|
74 | 74 | $error = 'Missing @return tag in function comment'; |
75 | - $phpcsFile->addError($error, $stackPtr, 'Missing'); |
|
75 | + $phpcsFile->addError( $error, $stackPtr, 'Missing' ); |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | |
79 | 79 | // Constructor/destructor should not have @return |
80 | - if ($commentWithReturn) { |
|
80 | + if ( $commentWithReturn ) { |
|
81 | 81 | $error = 'Unexpected @return tag in constructor/destructor comment'; |
82 | - $phpcsFile->addFixableError($error, $commentWithReturn, 'Unexpected'); |
|
83 | - if ($phpcsFile->fixer->enabled === true) { |
|
84 | - $phpcsFile->fixer->replaceToken($commentWithReturn, ''); |
|
82 | + $phpcsFile->addFixableError( $error, $commentWithReturn, 'Unexpected' ); |
|
83 | + if ( $phpcsFile->fixer->enabled === true ) { |
|
84 | + $phpcsFile->fixer->replaceToken( $commentWithReturn, '' ); |
|
85 | 85 | } |
86 | 86 | return; |
87 | 87 | } |
@@ -42,22 +42,22 @@ discard block |
||
42 | 42 | * @inheritDoc |
43 | 43 | */ |
44 | 44 | public function register() { |
45 | - return [T_DOC_COMMENT_OPEN_TAG]; |
|
45 | + return [ T_DOC_COMMENT_OPEN_TAG ]; |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @inheritDoc |
51 | 51 | */ |
52 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
52 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
|
53 | 53 | $tokens = $phpcsFile->getTokens(); |
54 | 54 | $commentStart = $stackPtr; |
55 | - $commentEnd = $tokens[$stackPtr]['comment_closer']; |
|
55 | + $commentEnd = $tokens[ $stackPtr ][ 'comment_closer' ]; |
|
56 | 56 | |
57 | - $indentationLevel = $this->getIndentationLevel($phpcsFile, $stackPtr); |
|
57 | + $indentationLevel = $this->getIndentationLevel( $phpcsFile, $stackPtr ); |
|
58 | 58 | |
59 | 59 | // Skip for inline comments |
60 | - if ($indentationLevel > 1) { |
|
60 | + if ( $indentationLevel > 1 ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
@@ -66,56 +66,56 @@ discard block |
||
66 | 66 | T_DOC_COMMENT_STAR, |
67 | 67 | ]; |
68 | 68 | |
69 | - $short = $phpcsFile->findNext($empty, ($stackPtr + 1), $commentEnd, true); |
|
70 | - if ($short === false) { |
|
69 | + $short = $phpcsFile->findNext( $empty, ( $stackPtr + 1 ), $commentEnd, true ); |
|
70 | + if ( $short === false ) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | // The first line of the comment should just be the /** code. |
75 | - if ($tokens[$short]['line'] === $tokens[$stackPtr]['line']) { |
|
75 | + if ( $tokens[ $short ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) { |
|
76 | 76 | $error = 'The open comment tag must be the only content on the line'; |
77 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen'); |
|
78 | - if ($fix === true) { |
|
79 | - $indentation = $tokens[$commentStart]['column'] - 1; |
|
80 | - $indentation = str_repeat("\t", $indentation); |
|
77 | + $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'ContentAfterOpen' ); |
|
78 | + if ( $fix === true ) { |
|
79 | + $indentation = $tokens[ $commentStart ][ 'column' ] - 1; |
|
80 | + $indentation = str_repeat( "\t", $indentation ); |
|
81 | 81 | |
82 | 82 | $phpcsFile->fixer->beginChangeset(); |
83 | - $phpcsFile->fixer->addContentBefore($short, $indentation . ' * '); |
|
84 | - $phpcsFile->fixer->addNewlineBefore($short); |
|
83 | + $phpcsFile->fixer->addContentBefore( $short, $indentation . ' * ' ); |
|
84 | + $phpcsFile->fixer->addNewlineBefore( $short ); |
|
85 | 85 | $phpcsFile->fixer->endChangeset(); |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | 89 | // The last line of the comment should just be the */ code. |
90 | - $prev = $phpcsFile->findPrevious($empty, ($commentEnd - 1), $stackPtr, true); |
|
91 | - if ($tokens[$prev]['line'] === $tokens[$commentEnd]['line']) { |
|
90 | + $prev = $phpcsFile->findPrevious( $empty, ( $commentEnd - 1 ), $stackPtr, true ); |
|
91 | + if ( $tokens[ $prev ][ 'line' ] === $tokens[ $commentEnd ][ 'line' ] ) { |
|
92 | 92 | $error = 'The close comment tag must be the only content on the line'; |
93 | - $fix = $phpcsFile->addFixableError($error, $commentEnd, 'ContentBeforeClose'); |
|
94 | - if ($fix === true) { |
|
95 | - $indentation = $tokens[$commentStart]['column'] - 1; |
|
96 | - $indentation = str_repeat("\t", $indentation); |
|
93 | + $fix = $phpcsFile->addFixableError( $error, $commentEnd, 'ContentBeforeClose' ); |
|
94 | + if ( $fix === true ) { |
|
95 | + $indentation = $tokens[ $commentStart ][ 'column' ] - 1; |
|
96 | + $indentation = str_repeat( "\t", $indentation ); |
|
97 | 97 | |
98 | 98 | $phpcsFile->fixer->beginChangeset(); |
99 | 99 | |
100 | - $phpcsFile->fixer->replaceToken($commentEnd, $indentation . ' ' . $tokens[$commentEnd]['content']); |
|
101 | - $phpcsFile->fixer->addNewlineBefore($commentEnd); |
|
100 | + $phpcsFile->fixer->replaceToken( $commentEnd, $indentation . ' ' . $tokens[ $commentEnd ][ 'content' ] ); |
|
101 | + $phpcsFile->fixer->addNewlineBefore( $commentEnd ); |
|
102 | 102 | |
103 | 103 | $phpcsFile->fixer->endChangeset(); |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | 107 | // Check for additional blank lines at the end of the comment. |
108 | - if ($tokens[$prev]['line'] < ($tokens[$commentEnd]['line'] - 1)) { |
|
108 | + if ( $tokens[ $prev ][ 'line' ] < ( $tokens[ $commentEnd ][ 'line' ] - 1 ) ) { |
|
109 | 109 | $error = 'Additional blank lines found at end of doc comment'; |
110 | - $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter'); |
|
111 | - if ($fix === true) { |
|
110 | + $fix = $phpcsFile->addFixableError( $error, $commentEnd, 'SpacingAfter' ); |
|
111 | + if ( $fix === true ) { |
|
112 | 112 | $phpcsFile->fixer->beginChangeset(); |
113 | - for ($i = ($prev + 1); $i < $commentEnd; $i++) { |
|
114 | - if ($tokens[($i + 1)]['line'] === $tokens[$commentEnd]['line']) { |
|
113 | + for ( $i = ( $prev + 1 ); $i < $commentEnd; $i++ ) { |
|
114 | + if ( $tokens[ ( $i + 1 ) ][ 'line' ] === $tokens[ $commentEnd ][ 'line' ] ) { |
|
115 | 115 | break; |
116 | 116 | } |
117 | 117 | |
118 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
118 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | $phpcsFile->fixer->endChangeset(); |
@@ -123,20 +123,20 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | // No extra newline before short description. |
126 | - if ($tokens[$short]['line'] !== ($tokens[$stackPtr]['line'] + 1)) { |
|
126 | + if ( $tokens[ $short ][ 'line' ] !== ( $tokens[ $stackPtr ][ 'line' ] + 1 ) ) { |
|
127 | 127 | $error = 'Doc comment short description must be on the first line'; |
128 | - $fix = $phpcsFile->addFixableError($error, $short, 'SpacingBeforeShort'); |
|
129 | - if ($fix === true) { |
|
128 | + $fix = $phpcsFile->addFixableError( $error, $short, 'SpacingBeforeShort' ); |
|
129 | + if ( $fix === true ) { |
|
130 | 130 | $phpcsFile->fixer->beginChangeset(); |
131 | - for ($i = $stackPtr; $i < $short; $i++) { |
|
132 | - if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { |
|
131 | + for ( $i = $stackPtr; $i < $short; $i++ ) { |
|
132 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - if ($tokens[$i]['line'] === $tokens[$short]['line']) { |
|
135 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $short ][ 'line' ] ) { |
|
136 | 136 | break; |
137 | 137 | } |
138 | 138 | |
139 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
139 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | $phpcsFile->fixer->endChangeset(); |
@@ -145,12 +145,12 @@ discard block |
||
145 | 145 | |
146 | 146 | // Account for the fact that a short description might cover |
147 | 147 | // multiple lines. |
148 | - $shortContent = $tokens[$short]['content']; |
|
148 | + $shortContent = $tokens[ $short ][ 'content' ]; |
|
149 | 149 | $shortEnd = $short; |
150 | - for ($i = ($short + 1); $i < $commentEnd; $i++) { |
|
151 | - if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { |
|
152 | - if ($tokens[$i]['line'] === ($tokens[$shortEnd]['line'] + 1)) { |
|
153 | - $shortContent .= $tokens[$i]['content']; |
|
150 | + for ( $i = ( $short + 1 ); $i < $commentEnd; $i++ ) { |
|
151 | + if ( $tokens[ $i ][ 'code' ] === T_DOC_COMMENT_STRING ) { |
|
152 | + if ( $tokens[ $i ][ 'line' ] === ( $tokens[ $shortEnd ][ 'line' ] + 1 ) ) { |
|
153 | + $shortContent .= $tokens[ $i ][ 'content' ]; |
|
154 | 154 | $shortEnd = $i; |
155 | 155 | } else { |
156 | 156 | break; |
@@ -158,32 +158,32 @@ discard block |
||
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - if (empty($tokens[$commentStart]['comment_tags']) === true) { |
|
161 | + if ( empty( $tokens[ $commentStart ][ 'comment_tags' ] ) === true ) { |
|
162 | 162 | // No tags in the comment. |
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | - $firstTag = $tokens[$commentStart]['comment_tags'][0]; |
|
167 | - if ($tokens[$firstTag]['line'] === $tokens[$commentStart]['line'] + 1) { |
|
166 | + $firstTag = $tokens[ $commentStart ][ 'comment_tags' ][ 0 ]; |
|
167 | + if ( $tokens[ $firstTag ][ 'line' ] === $tokens[ $commentStart ][ 'line' ] + 1 ) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - $prev = $phpcsFile->findPrevious($empty, ($firstTag - 1), $stackPtr, true); |
|
172 | - if ($tokens[$firstTag]['line'] !== ($tokens[$prev]['line'] + 2)) { |
|
171 | + $prev = $phpcsFile->findPrevious( $empty, ( $firstTag - 1 ), $stackPtr, true ); |
|
172 | + if ( $tokens[ $firstTag ][ 'line' ] !== ( $tokens[ $prev ][ 'line' ] + 2 ) ) { |
|
173 | 173 | $error = 'There must be exactly one blank line before the tags in a doc comment'; |
174 | - $fix = $phpcsFile->addFixableError($error, $firstTag, 'SpacingBeforeTags'); |
|
175 | - if ($fix === true) { |
|
174 | + $fix = $phpcsFile->addFixableError( $error, $firstTag, 'SpacingBeforeTags' ); |
|
175 | + if ( $fix === true ) { |
|
176 | 176 | $phpcsFile->fixer->beginChangeset(); |
177 | - for ($i = ($prev + 1); $i < $firstTag; $i++) { |
|
178 | - if ($tokens[$i]['line'] === $tokens[$firstTag]['line']) { |
|
177 | + for ( $i = ( $prev + 1 ); $i < $firstTag; $i++ ) { |
|
178 | + if ( $tokens[ $i ][ 'line' ] === $tokens[ $firstTag ][ 'line' ] ) { |
|
179 | 179 | break; |
180 | 180 | } |
181 | 181 | |
182 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
182 | + $phpcsFile->fixer->replaceToken( $i, '' ); |
|
183 | 183 | } |
184 | 184 | |
185 | - $indent = str_repeat("\t", $tokens[$stackPtr]['column'] - 1) . ' '; |
|
186 | - $phpcsFile->fixer->addContent($prev, $phpcsFile->eolChar . $indent . '*' . $phpcsFile->eolChar); |
|
185 | + $indent = str_repeat( "\t", $tokens[ $stackPtr ][ 'column' ] - 1 ) . ' '; |
|
186 | + $phpcsFile->fixer->addContent( $prev, $phpcsFile->eolChar . $indent . '*' . $phpcsFile->eolChar ); |
|
187 | 187 | $phpcsFile->fixer->endChangeset(); |
188 | 188 | } |
189 | 189 | } |
@@ -29,46 +29,46 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @inheritDoc |
31 | 31 | */ |
32 | - public function process(PHP_CodeSniffer_File $phpCsFile, $stackPointer) { |
|
32 | + public function process( PHP_CodeSniffer_File $phpCsFile, $stackPointer ) { |
|
33 | 33 | $tokens = $phpCsFile->getTokens(); |
34 | 34 | |
35 | - $docBlockEndIndex = $this->findRelatedDocBlock($phpCsFile, $stackPointer); |
|
35 | + $docBlockEndIndex = $this->findRelatedDocBlock( $phpCsFile, $stackPointer ); |
|
36 | 36 | |
37 | - if (!$docBlockEndIndex) { |
|
37 | + if ( ! $docBlockEndIndex ) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener']; |
|
41 | + $docBlockStartIndex = $tokens[ $docBlockEndIndex ][ 'comment_opener' ]; |
|
42 | 42 | |
43 | - for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) { |
|
44 | - if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') { |
|
43 | + for ( $i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++ ) { |
|
44 | + if ( $tokens[ $i ][ 'type' ] !== 'T_DOC_COMMENT_TAG' ) { |
|
45 | 45 | continue; |
46 | 46 | } |
47 | - if (!in_array($tokens[$i]['content'], ['@return', '@param'])) { |
|
47 | + if ( ! in_array( $tokens[ $i ][ 'content' ], [ '@return', '@param' ] ) ) { |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
51 | 51 | $classNameIndex = $i + 2; |
52 | 52 | |
53 | - if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') { |
|
53 | + if ( $tokens[ $classNameIndex ][ 'type' ] !== 'T_DOC_COMMENT_STRING' ) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - $content = $tokens[$classNameIndex]['content']; |
|
57 | + $content = $tokens[ $classNameIndex ][ 'content' ]; |
|
58 | 58 | |
59 | 59 | $appendix = ''; |
60 | - $spaceIndex = strpos($content, ' '); |
|
61 | - if ($spaceIndex) { |
|
62 | - $appendix = substr($content, $spaceIndex); |
|
63 | - $content = substr($content, 0, $spaceIndex); |
|
60 | + $spaceIndex = strpos( $content, ' ' ); |
|
61 | + if ( $spaceIndex ) { |
|
62 | + $appendix = substr( $content, $spaceIndex ); |
|
63 | + $content = substr( $content, 0, $spaceIndex ); |
|
64 | 64 | } |
65 | 65 | |
66 | - if (empty($content)) { |
|
66 | + if ( empty( $content ) ) { |
|
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | |
70 | - $parts = explode('|', $content); |
|
71 | - $this->fixParts($phpCsFile, $classNameIndex, $parts, $appendix); |
|
70 | + $parts = explode( '|', $content ); |
|
71 | + $this->fixParts( $phpCsFile, $classNameIndex, $parts, $appendix ); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -80,35 +80,35 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return void |
82 | 82 | */ |
83 | - protected function fixParts(PHP_CodeSniffer_File $phpCsFile, $classNameIndex, array $parts, $appendix) { |
|
83 | + protected function fixParts( PHP_CodeSniffer_File $phpCsFile, $classNameIndex, array $parts, $appendix ) { |
|
84 | 84 | $mapping = [ |
85 | 85 | 'boolean' => 'bool', |
86 | 86 | 'integer' => 'int', |
87 | 87 | ]; |
88 | 88 | |
89 | - $result = []; |
|
90 | - foreach ($parts as $key => $part) { |
|
91 | - if (!isset($mapping[$part])) { |
|
89 | + $result = [ ]; |
|
90 | + foreach ( $parts as $key => $part ) { |
|
91 | + if ( ! isset( $mapping[ $part ] ) ) { |
|
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | |
95 | - $parts[$key] = $mapping[$part]; |
|
96 | - $result[$part] = $mapping[$part]; |
|
95 | + $parts[ $key ] = $mapping[ $part ]; |
|
96 | + $result[ $part ] = $mapping[ $part ]; |
|
97 | 97 | } |
98 | 98 | |
99 | - if (!$result) { |
|
99 | + if ( ! $result ) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - $message = []; |
|
104 | - foreach ($result as $part => $useStatement) { |
|
105 | - $message[] = $part . ' => ' . $useStatement; |
|
103 | + $message = [ ]; |
|
104 | + foreach ( $result as $part => $useStatement ) { |
|
105 | + $message[ ] = $part . ' => ' . $useStatement; |
|
106 | 106 | } |
107 | 107 | |
108 | - $fix = $phpCsFile->addFixableError(implode(', ', $message), $classNameIndex); |
|
109 | - if ($fix) { |
|
110 | - $newContent = implode('|', $parts); |
|
111 | - $phpCsFile->fixer->replaceToken($classNameIndex, $newContent . $appendix); |
|
108 | + $fix = $phpCsFile->addFixableError( implode( ', ', $message ), $classNameIndex ); |
|
109 | + if ( $fix ) { |
|
110 | + $newContent = implode( '|', $parts ); |
|
111 | + $phpCsFile->fixer->replaceToken( $classNameIndex, $newContent . $appendix ); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 |
@@ -29,46 +29,46 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @inheritDoc |
31 | 31 | */ |
32 | - public function process(PHP_CodeSniffer_File $phpCsFile, $stackPointer) { |
|
32 | + public function process( PHP_CodeSniffer_File $phpCsFile, $stackPointer ) { |
|
33 | 33 | $tokens = $phpCsFile->getTokens(); |
34 | 34 | |
35 | - $docBlockEndIndex = $this->findRelatedDocBlock($phpCsFile, $stackPointer); |
|
35 | + $docBlockEndIndex = $this->findRelatedDocBlock( $phpCsFile, $stackPointer ); |
|
36 | 36 | |
37 | - if (!$docBlockEndIndex) { |
|
37 | + if ( ! $docBlockEndIndex ) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener']; |
|
41 | + $docBlockStartIndex = $tokens[ $docBlockEndIndex ][ 'comment_opener' ]; |
|
42 | 42 | |
43 | - for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) { |
|
44 | - if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') { |
|
43 | + for ( $i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++ ) { |
|
44 | + if ( $tokens[ $i ][ 'type' ] !== 'T_DOC_COMMENT_TAG' ) { |
|
45 | 45 | continue; |
46 | 46 | } |
47 | - if (!in_array($tokens[$i]['content'], ['@return'])) { |
|
47 | + if ( ! in_array( $tokens[ $i ][ 'content' ], [ '@return' ] ) ) { |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
51 | 51 | $classNameIndex = $i + 2; |
52 | 52 | |
53 | - if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') { |
|
53 | + if ( $tokens[ $classNameIndex ][ 'type' ] !== 'T_DOC_COMMENT_STRING' ) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - $content = $tokens[$classNameIndex]['content']; |
|
57 | + $content = $tokens[ $classNameIndex ][ 'content' ]; |
|
58 | 58 | |
59 | 59 | $appendix = ''; |
60 | - $spaceIndex = strpos($content, ' '); |
|
61 | - if ($spaceIndex) { |
|
62 | - $appendix = substr($content, $spaceIndex); |
|
63 | - $content = substr($content, 0, $spaceIndex); |
|
60 | + $spaceIndex = strpos( $content, ' ' ); |
|
61 | + if ( $spaceIndex ) { |
|
62 | + $appendix = substr( $content, $spaceIndex ); |
|
63 | + $content = substr( $content, 0, $spaceIndex ); |
|
64 | 64 | } |
65 | 65 | |
66 | - if (empty($content)) { |
|
66 | + if ( empty( $content ) ) { |
|
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | |
70 | - $parts = explode('|', $content); |
|
71 | - $this->fixParts($phpCsFile, $classNameIndex, $parts, $appendix); |
|
70 | + $parts = explode( '|', $content ); |
|
71 | + $this->fixParts( $phpCsFile, $classNameIndex, $parts, $appendix ); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -80,30 +80,30 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return void |
82 | 82 | */ |
83 | - protected function fixParts(PHP_CodeSniffer_File $phpCsFile, $classNameIndex, array $parts, $appendix) { |
|
84 | - $result = []; |
|
85 | - foreach ($parts as $key => $part) { |
|
86 | - if ($part !== 'self') { |
|
83 | + protected function fixParts( PHP_CodeSniffer_File $phpCsFile, $classNameIndex, array $parts, $appendix ) { |
|
84 | + $result = [ ]; |
|
85 | + foreach ( $parts as $key => $part ) { |
|
86 | + if ( $part !== 'self' ) { |
|
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | - $parts[$key] = '$this'; |
|
91 | - $result[$part] = '$this'; |
|
90 | + $parts[ $key ] = '$this'; |
|
91 | + $result[ $part ] = '$this'; |
|
92 | 92 | } |
93 | 93 | |
94 | - if (!$result) { |
|
94 | + if ( ! $result ) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - $message = []; |
|
99 | - foreach ($result as $part => $useStatement) { |
|
100 | - $message[] = $part . ' => ' . $useStatement; |
|
98 | + $message = [ ]; |
|
99 | + foreach ( $result as $part => $useStatement ) { |
|
100 | + $message[ ] = $part . ' => ' . $useStatement; |
|
101 | 101 | } |
102 | 102 | |
103 | - $fix = $phpCsFile->addFixableError(implode(', ', $message), $classNameIndex); |
|
104 | - if ($fix) { |
|
105 | - $newContent = implode('|', $parts); |
|
106 | - $phpCsFile->fixer->replaceToken($classNameIndex, $newContent . $appendix); |
|
103 | + $fix = $phpCsFile->addFixableError( implode( ', ', $message ), $classNameIndex ); |
|
104 | + if ( $fix ) { |
|
105 | + $newContent = implode( '|', $parts ); |
|
106 | + $phpCsFile->fixer->replaceToken( $classNameIndex, $newContent . $appendix ); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | * @inheritDoc |
19 | 19 | */ |
20 | 20 | public function register() { |
21 | - return [T_DOC_COMMENT]; |
|
21 | + return [ T_DOC_COMMENT ]; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @inheritDoc |
26 | 26 | */ |
27 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
27 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
|
28 | 28 | $tokens = $phpcsFile->getTokens(); |
29 | 29 | |
30 | 30 | // We are only interested in function/class/interface doc block comments. |
31 | - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
31 | + $nextToken = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
32 | 32 | $ignore = [ |
33 | 33 | T_CLASS, |
34 | 34 | T_INTERFACE, |
@@ -40,29 +40,29 @@ discard block |
||
40 | 40 | T_ABSTRACT, |
41 | 41 | ]; |
42 | 42 | |
43 | - if (in_array($tokens[$nextToken]['code'], $ignore) === false) { |
|
43 | + if ( in_array( $tokens[ $nextToken ][ 'code' ], $ignore ) === false ) { |
|
44 | 44 | // Could be a file comment. |
45 | - $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
46 | - if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) { |
|
45 | + $prevToken = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
46 | + if ( $tokens[ $prevToken ][ 'code' ] !== T_OPEN_TAG ) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | // We only want to get the first comment in a block. If there is |
52 | 52 | // a comment on the line before this one, return. |
53 | - $docComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($stackPtr - 1)); |
|
54 | - if ($docComment !== false) { |
|
55 | - if ($tokens[$docComment]['line'] === ($tokens[$stackPtr]['line'] - 1)) { |
|
53 | + $docComment = $phpcsFile->findPrevious( T_DOC_COMMENT, ( $stackPtr - 1 ) ); |
|
54 | + if ( $docComment !== false ) { |
|
55 | + if ( $tokens[ $docComment ][ 'line' ] === ( $tokens[ $stackPtr ][ 'line' ] - 1 ) ) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | - $comments = [$stackPtr]; |
|
60 | + $comments = [ $stackPtr ]; |
|
61 | 61 | $currentComment = $stackPtr; |
62 | 62 | $lastComment = $stackPtr; |
63 | - while (($currentComment = $phpcsFile->findNext(T_DOC_COMMENT, ($currentComment + 1))) !== false) { |
|
64 | - if ($tokens[$lastComment]['line'] === ($tokens[$currentComment]['line'] - 1)) { |
|
65 | - $comments[] = $currentComment; |
|
63 | + while ( ( $currentComment = $phpcsFile->findNext( T_DOC_COMMENT, ( $currentComment + 1 ) ) ) !== false ) { |
|
64 | + if ( $tokens[ $lastComment ][ 'line' ] === ( $tokens[ $currentComment ][ 'line' ] - 1 ) ) { |
|
65 | + $comments[ ] = $currentComment; |
|
66 | 66 | $lastComment = $currentComment; |
67 | 67 | } else { |
68 | 68 | break; |
@@ -70,30 +70,30 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | // The $comments array now contains pointers to each token in the comment block. |
73 | - $requiredColumn = strpos($tokens[$stackPtr]['content'], '*'); |
|
74 | - $requiredColumn += $tokens[$stackPtr]['column']; |
|
73 | + $requiredColumn = strpos( $tokens[ $stackPtr ][ 'content' ], '*' ); |
|
74 | + $requiredColumn += $tokens[ $stackPtr ][ 'column' ]; |
|
75 | 75 | |
76 | - foreach ($comments as $commentPointer) { |
|
76 | + foreach ( $comments as $commentPointer ) { |
|
77 | 77 | // Check the spacing after each asterisk. |
78 | - $content = $tokens[$commentPointer]['content']; |
|
79 | - $firstChar = substr($content, 0, 1); |
|
80 | - $lastChar = substr($content, -1); |
|
81 | - if ($firstChar === '/' || $lastChar !== '/') { |
|
78 | + $content = $tokens[ $commentPointer ][ 'content' ]; |
|
79 | + $firstChar = substr( $content, 0, 1 ); |
|
80 | + $lastChar = substr( $content, -1 ); |
|
81 | + if ( $firstChar === '/' || $lastChar !== '/' ) { |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - $count = substr_count($content, '*'); |
|
86 | - if ($count < 2) { |
|
85 | + $count = substr_count( $content, '*' ); |
|
86 | + if ( $count < 2 ) { |
|
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $error = 'Expected 1 asterisk on closing line; %s found'; |
91 | - $data = [$count]; |
|
92 | - $fix = $phpcsFile->addFixableError($error, $commentPointer, 'SpaceBeforeTag', $data); |
|
93 | - if ($fix === true && $phpcsFile->fixer->enabled === true) { |
|
94 | - $pos = strpos($content, '*'); |
|
95 | - $content = substr($content, 0, $pos + 1) . substr($content, $pos + $count); |
|
96 | - $phpcsFile->fixer->replaceToken($commentPointer, $content); |
|
91 | + $data = [ $count ]; |
|
92 | + $fix = $phpcsFile->addFixableError( $error, $commentPointer, 'SpaceBeforeTag', $data ); |
|
93 | + if ( $fix === true && $phpcsFile->fixer->enabled === true ) { |
|
94 | + $pos = strpos( $content, '*' ); |
|
95 | + $content = substr( $content, 0, $pos + 1 ) . substr( $content, $pos + $count ); |
|
96 | + $phpcsFile->fixer->replaceToken( $commentPointer, $content ); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
@@ -25,49 +25,49 @@ |
||
25 | 25 | /** |
26 | 26 | * @inheritDoc |
27 | 27 | */ |
28 | - public function process(PHP_CodeSniffer_File $phpCsFile, $stackPointer) { |
|
28 | + public function process( PHP_CodeSniffer_File $phpCsFile, $stackPointer ) { |
|
29 | 29 | $tokens = $phpCsFile->getTokens(); |
30 | 30 | |
31 | - $docBlockEndIndex = $this->findRelatedDocBlock($phpCsFile, $stackPointer); |
|
31 | + $docBlockEndIndex = $this->findRelatedDocBlock( $phpCsFile, $stackPointer ); |
|
32 | 32 | |
33 | - if (!$docBlockEndIndex) { |
|
33 | + if ( ! $docBlockEndIndex ) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener']; |
|
37 | + $docBlockStartIndex = $tokens[ $docBlockEndIndex ][ 'comment_opener' ]; |
|
38 | 38 | |
39 | - for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) { |
|
40 | - if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') { |
|
39 | + for ( $i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++ ) { |
|
40 | + if ( $tokens[ $i ][ 'type' ] !== 'T_DOC_COMMENT_TAG' ) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | - if (!in_array($tokens[$i]['content'], ['@param'])) { |
|
43 | + if ( ! in_array( $tokens[ $i ][ 'content' ], [ '@param' ] ) ) { |
|
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $classNameIndex = $i + 2; |
48 | 48 | |
49 | - if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') { |
|
49 | + if ( $tokens[ $classNameIndex ][ 'type' ] !== 'T_DOC_COMMENT_STRING' ) { |
|
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | - $content = $tokens[$classNameIndex]['content']; |
|
53 | + $content = $tokens[ $classNameIndex ][ 'content' ]; |
|
54 | 54 | |
55 | 55 | $appendix = ''; |
56 | - $spaceIndex = strpos($content, ' '); |
|
57 | - if ($spaceIndex) { |
|
58 | - $appendix = substr($content, $spaceIndex); |
|
59 | - $content = substr($content, 0, $spaceIndex); |
|
56 | + $spaceIndex = strpos( $content, ' ' ); |
|
57 | + if ( $spaceIndex ) { |
|
58 | + $appendix = substr( $content, $spaceIndex ); |
|
59 | + $content = substr( $content, 0, $spaceIndex ); |
|
60 | 60 | } |
61 | - if (empty($content) || strpos($content, '|') !== false) { |
|
61 | + if ( empty( $content ) || strpos( $content, '|' ) !== false ) { |
|
62 | 62 | continue; |
63 | 63 | } |
64 | 64 | |
65 | - if (!in_array($content, ['null', 'false', 'true'], true)) { |
|
65 | + if ( ! in_array( $content, [ 'null', 'false', 'true' ], true ) ) { |
|
66 | 66 | continue; |
67 | 67 | } |
68 | 68 | |
69 | 69 | $error = 'Possible doc block error: `' . $content . '` as only param type does not seem right. Makes this a no-op.'; |
70 | - $phpCsFile->addWarning($error, $i); |
|
70 | + $phpCsFile->addWarning( $error, $i ); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 |
@@ -25,53 +25,53 @@ |
||
25 | 25 | /** |
26 | 26 | * @inheritDoc |
27 | 27 | */ |
28 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
28 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
|
29 | 29 | $tokens = $phpcsFile->getTokens(); |
30 | 30 | |
31 | 31 | $description = ''; |
32 | - $content = $tokens[$stackPtr]['content']; |
|
32 | + $content = $tokens[ $stackPtr ][ 'content' ]; |
|
33 | 33 | |
34 | 34 | $hint = $content; |
35 | - if (strpos($hint, ' ') !== false) { |
|
36 | - list($hint, $description) = explode(' ', $hint, 2); |
|
35 | + if ( strpos( $hint, ' ' ) !== false ) { |
|
36 | + list( $hint, $description ) = explode( ' ', $hint, 2 ); |
|
37 | 37 | } |
38 | 38 | |
39 | - if (strpos($hint, '|') === false) { |
|
39 | + if ( strpos( $hint, '|' ) === false ) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
43 | - $pieces = explode('|', $hint); |
|
43 | + $pieces = explode( '|', $hint ); |
|
44 | 44 | |
45 | - $hints = []; |
|
46 | - foreach ($pieces as $piece) { |
|
47 | - $hints[] = trim($piece); |
|
45 | + $hints = [ ]; |
|
46 | + foreach ( $pieces as $piece ) { |
|
47 | + $hints[ ] = trim( $piece ); |
|
48 | 48 | } |
49 | 49 | |
50 | - $desc = trim($description); |
|
50 | + $desc = trim( $description ); |
|
51 | 51 | |
52 | - while (!empty($desc) && mb_substr($desc, 0, 1) === '|') { |
|
53 | - $desc = trim(mb_substr($desc, 1)); |
|
52 | + while ( ! empty( $desc ) && mb_substr( $desc, 0, 1 ) === '|' ) { |
|
53 | + $desc = trim( mb_substr( $desc, 1 ) ); |
|
54 | 54 | |
55 | - $pos = mb_strpos($desc, ' '); |
|
56 | - if ($pos > 0) { |
|
57 | - $hints[] = trim(mb_substr($desc, 0, $pos)); |
|
58 | - $desc = trim(mb_substr($desc, $pos)); |
|
55 | + $pos = mb_strpos( $desc, ' ' ); |
|
56 | + if ( $pos > 0 ) { |
|
57 | + $hints[ ] = trim( mb_substr( $desc, 0, $pos ) ); |
|
58 | + $desc = trim( mb_substr( $desc, $pos ) ); |
|
59 | 59 | } else { |
60 | - $hints[] = $desc; |
|
60 | + $hints[ ] = $desc; |
|
61 | 61 | $desc = ''; |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | - if ($desc !== '') { |
|
65 | + if ( $desc !== '' ) { |
|
66 | 66 | $desc = ' ' . $desc; |
67 | 67 | } |
68 | 68 | |
69 | - $newContent = implode('|', $hints) . $desc; |
|
69 | + $newContent = implode( '|', $hints ) . $desc; |
|
70 | 70 | |
71 | - if ($newContent !== $content) { |
|
72 | - $fix = $phpcsFile->addFixableError('There should be no space around pipes in doc blocks.', $stackPtr); |
|
73 | - if ($fix) { |
|
74 | - $phpcsFile->fixer->replaceToken($stackPtr, $newContent); |
|
71 | + if ( $newContent !== $content ) { |
|
72 | + $fix = $phpcsFile->addFixableError( 'There should be no space around pipes in doc blocks.', $stackPtr ); |
|
73 | + if ( $fix ) { |
|
74 | + $phpcsFile->fixer->replaceToken( $stackPtr, $newContent ); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | } |
@@ -94,60 +94,60 @@ discard block |
||
94 | 94 | * @inheritDoc |
95 | 95 | */ |
96 | 96 | public function register() { |
97 | - return [T_CLASS, T_FUNCTION]; |
|
97 | + return [ T_CLASS, T_FUNCTION ]; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @inheritDoc |
102 | 102 | */ |
103 | - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { |
|
103 | + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
|
104 | 104 | $tokens = $phpcsFile->getTokens(); |
105 | 105 | |
106 | - $docBlockEndIndex = $this->findRelatedDocBlock($phpcsFile, $stackPtr); |
|
107 | - if (!$docBlockEndIndex) { |
|
106 | + $docBlockEndIndex = $this->findRelatedDocBlock( $phpcsFile, $stackPtr ); |
|
107 | + if ( ! $docBlockEndIndex ) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | 110 | |
111 | - $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener']; |
|
111 | + $docBlockStartIndex = $tokens[ $docBlockEndIndex ][ 'comment_opener' ]; |
|
112 | 112 | |
113 | 113 | $this->prepareWhitelist(); |
114 | 114 | |
115 | - for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) { |
|
116 | - if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') { |
|
115 | + for ( $i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++ ) { |
|
116 | + if ( $tokens[ $i ][ 'type' ] !== 'T_DOC_COMMENT_TAG' ) { |
|
117 | 117 | continue; |
118 | 118 | } |
119 | - if (in_array($tokens[$i]['content'], self::$whitelistedTags)) { |
|
119 | + if ( in_array( $tokens[ $i ][ 'content' ], self::$whitelistedTags ) ) { |
|
120 | 120 | continue; |
121 | 121 | } |
122 | 122 | |
123 | - $error = 'Unexpected tag type `' . $tokens[$i]['content'] . '` in doc block'; |
|
124 | - if (!in_array($tokens[$i]['content'], self::$blacklistedTags, true) && !isset(self::$mapping[$tokens[$i]['content']])) { |
|
125 | - $phpcsFile->addWarning($error, $i, 'Unknown'); |
|
123 | + $error = 'Unexpected tag type `' . $tokens[ $i ][ 'content' ] . '` in doc block'; |
|
124 | + if ( ! in_array( $tokens[ $i ][ 'content' ], self::$blacklistedTags, true ) && ! isset( self::$mapping[ $tokens[ $i ][ 'content' ] ] ) ) { |
|
125 | + $phpcsFile->addWarning( $error, $i, 'Unknown' ); |
|
126 | 126 | continue; |
127 | 127 | } |
128 | 128 | |
129 | - $mappingTag = isset(self::$mapping[$tokens[$i]['content']]) ? self::$mapping[$tokens[$i]['content']] : null; |
|
130 | - if ($mappingTag) { |
|
129 | + $mappingTag = isset( self::$mapping[ $tokens[ $i ][ 'content' ] ] ) ? self::$mapping[ $tokens[ $i ][ 'content' ] ] : null; |
|
130 | + if ( $mappingTag ) { |
|
131 | 131 | $error .= ', expected `' . $mappingTag . '`'; |
132 | 132 | } |
133 | 133 | |
134 | - $prevAsterix = $phpcsFile->findPrevious(T_DOC_COMMENT_STAR, $i - 1, $docBlockStartIndex); |
|
135 | - $nextAsterix = $phpcsFile->findNext([T_DOC_COMMENT_STAR, T_DOC_COMMENT_CLOSE_TAG], $i + 1, $docBlockEndIndex + 1); |
|
136 | - if (!$prevAsterix || !$nextAsterix) { |
|
137 | - $phpcsFile->addError($error, $i, 'Invalid'); |
|
134 | + $prevAsterix = $phpcsFile->findPrevious( T_DOC_COMMENT_STAR, $i - 1, $docBlockStartIndex ); |
|
135 | + $nextAsterix = $phpcsFile->findNext( [ T_DOC_COMMENT_STAR, T_DOC_COMMENT_CLOSE_TAG ], $i + 1, $docBlockEndIndex + 1 ); |
|
136 | + if ( ! $prevAsterix || ! $nextAsterix ) { |
|
137 | + $phpcsFile->addError( $error, $i, 'Invalid' ); |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | |
141 | - $phpcsFile->addFixableError($error, $i, 'Invalid'); |
|
142 | - if ($phpcsFile->fixer->enabled) { |
|
143 | - if ($mappingTag) { |
|
144 | - $phpcsFile->fixer->replaceToken($i, $mappingTag); |
|
141 | + $phpcsFile->addFixableError( $error, $i, 'Invalid' ); |
|
142 | + if ( $phpcsFile->fixer->enabled ) { |
|
143 | + if ( $mappingTag ) { |
|
144 | + $phpcsFile->fixer->replaceToken( $i, $mappingTag ); |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $phpcsFile->fixer->beginChangeset(); |
149 | - for ($j = $prevAsterix; $j < $nextAsterix; $j++) { |
|
150 | - $phpcsFile->fixer->replaceToken($j, ''); |
|
149 | + for ( $j = $prevAsterix; $j < $nextAsterix; $j++ ) { |
|
150 | + $phpcsFile->fixer->replaceToken( $j, '' ); |
|
151 | 151 | } |
152 | 152 | $phpcsFile->fixer->endChangeset(); |
153 | 153 | } |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @return void |
159 | 159 | */ |
160 | 160 | protected function prepareWhitelist() { |
161 | - if (!empty($this->whitelist)) { |
|
162 | - $whitelist = explode(',', $this->whitelist); |
|
163 | - foreach ($whitelist as $tag) { |
|
164 | - if (!in_array($tag, self::$whitelistedTags)) { |
|
165 | - self::$whitelistedTags[] = $tag; |
|
161 | + if ( ! empty( $this->whitelist ) ) { |
|
162 | + $whitelist = explode( ',', $this->whitelist ); |
|
163 | + foreach ( $whitelist as $tag ) { |
|
164 | + if ( ! in_array( $tag, self::$whitelistedTags ) ) { |
|
165 | + self::$whitelistedTags[ ] = $tag; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | } |
@@ -29,66 +29,66 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @inheritDoc |
31 | 31 | */ |
32 | - public function process(PHP_CodeSniffer_File $phpCsFile, $stackPointer) { |
|
32 | + public function process( PHP_CodeSniffer_File $phpCsFile, $stackPointer ) { |
|
33 | 33 | $tokens = $phpCsFile->getTokens(); |
34 | 34 | |
35 | - $docBlockEndIndex = $this->findRelatedDocBlock($phpCsFile, $stackPointer); |
|
35 | + $docBlockEndIndex = $this->findRelatedDocBlock( $phpCsFile, $stackPointer ); |
|
36 | 36 | |
37 | - if (!$docBlockEndIndex) { |
|
37 | + if ( ! $docBlockEndIndex ) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - $docBlockStartIndex = $tokens[$docBlockEndIndex]['comment_opener']; |
|
41 | + $docBlockStartIndex = $tokens[ $docBlockEndIndex ][ 'comment_opener' ]; |
|
42 | 42 | |
43 | - if ($this->hasInheritDoc($phpCsFile, $docBlockStartIndex, $docBlockEndIndex)) { |
|
43 | + if ( $this->hasInheritDoc( $phpCsFile, $docBlockStartIndex, $docBlockEndIndex ) ) { |
|
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
47 | - $docBlockParams = []; |
|
48 | - for ($i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++) { |
|
49 | - if ($tokens[$i]['type'] !== 'T_DOC_COMMENT_TAG') { |
|
47 | + $docBlockParams = [ ]; |
|
48 | + for ( $i = $docBlockStartIndex + 1; $i < $docBlockEndIndex; $i++ ) { |
|
49 | + if ( $tokens[ $i ][ 'type' ] !== 'T_DOC_COMMENT_TAG' ) { |
|
50 | 50 | continue; |
51 | 51 | } |
52 | - if (!in_array($tokens[$i]['content'], ['@param', '@return'])) { |
|
52 | + if ( ! in_array( $tokens[ $i ][ 'content' ], [ '@param', '@return' ] ) ) { |
|
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | 56 | $classNameIndex = $i + 2; |
57 | 57 | |
58 | - if ($tokens[$classNameIndex]['type'] !== 'T_DOC_COMMENT_STRING') { |
|
58 | + if ( $tokens[ $classNameIndex ][ 'type' ] !== 'T_DOC_COMMENT_STRING' ) { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - $content = $tokens[$classNameIndex]['content']; |
|
62 | + $content = $tokens[ $classNameIndex ][ 'content' ]; |
|
63 | 63 | |
64 | 64 | $appendix = ''; |
65 | - $spacePos = strpos($content, ' '); |
|
66 | - if ($spacePos) { |
|
67 | - $appendix = substr($content, $spacePos); |
|
68 | - $content = substr($content, 0, $spacePos); |
|
65 | + $spacePos = strpos( $content, ' ' ); |
|
66 | + if ( $spacePos ) { |
|
67 | + $appendix = substr( $content, $spacePos ); |
|
68 | + $content = substr( $content, 0, $spacePos ); |
|
69 | 69 | } |
70 | 70 | |
71 | - $pieces = explode('|', $content); |
|
71 | + $pieces = explode( '|', $content ); |
|
72 | 72 | |
73 | - if (!in_array('array', $pieces, true)) { |
|
73 | + if ( ! in_array( 'array', $pieces, true ) ) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | - if (!$this->containsTypeArray($pieces)) { |
|
76 | + if ( ! $this->containsTypeArray( $pieces ) ) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | 80 | $error = 'Doc Block param type `array` not needed on top of `...[]`'; |
81 | 81 | // For now just report |
82 | - $fix = $phpCsFile->addFixableError($error, $classNameIndex, 'TypeDuplicated'); |
|
83 | - if (!$fix) { |
|
82 | + $fix = $phpCsFile->addFixableError( $error, $classNameIndex, 'TypeDuplicated' ); |
|
83 | + if ( ! $fix ) { |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | - $keys = array_keys($pieces, 'array'); |
|
88 | - foreach ($keys as $key) { |
|
89 | - unset($pieces[$key]); |
|
87 | + $keys = array_keys( $pieces, 'array' ); |
|
88 | + foreach ( $keys as $key ) { |
|
89 | + unset( $pieces[ $key ] ); |
|
90 | 90 | } |
91 | - $content = implode('|', $pieces); |
|
91 | + $content = implode( '|', $pieces ); |
|
92 | 92 | |
93 | 93 | /* |
94 | 94 | var_dump($content); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | |
99 | 99 | $phpCsFile->fixer->beginChangeset(); |
100 | - $phpCsFile->fixer->replaceToken($classNameIndex, $content . $appendix); |
|
100 | + $phpCsFile->fixer->replaceToken( $classNameIndex, $content . $appendix ); |
|
101 | 101 | $phpCsFile->fixer->endChangeset(); |
102 | 102 | } |
103 | 103 | } |