@@ -25,7 +25,7 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @return array<int, int> |
| 27 | 27 | */ |
| 28 | - public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc') |
|
| 28 | + public function getErrorList($testFile = 'FunctionCallSignatureUnitTest.inc') |
|
| 29 | 29 | { |
| 30 | 30 | if ($testFile === 'FunctionCallSignatureUnitTest.js') { |
| 31 | 31 | return [ |
@@ -15,140 +15,140 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the lines where errors should occur. |
|
| 20 | - * |
|
| 21 | - * The key of the array should represent the line number and the value |
|
| 22 | - * should represent the number of errors that should occur on that line. |
|
| 23 | - * |
|
| 24 | - * @param string $testFile The name of the file being tested. |
|
| 25 | - * |
|
| 26 | - * @return array<int, int> |
|
| 27 | - */ |
|
| 28 | - public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc') |
|
| 29 | - { |
|
| 30 | - if ($testFile === 'FunctionCallSignatureUnitTest.js') { |
|
| 31 | - return [ |
|
| 32 | - 5 => 1, |
|
| 33 | - 6 => 2, |
|
| 34 | - 7 => 1, |
|
| 35 | - 8 => 1, |
|
| 36 | - 9 => 2, |
|
| 37 | - 10 => 3, |
|
| 38 | - 17 => 1, |
|
| 39 | - 18 => 1, |
|
| 40 | - 21 => 1, |
|
| 41 | - 24 => 1, |
|
| 42 | - 28 => 2, |
|
| 43 | - 30 => 2, |
|
| 44 | - 35 => 1, |
|
| 45 | - 49 => 1, |
|
| 46 | - 51 => 1, |
|
| 47 | - 54 => 1, |
|
| 48 | - 70 => 1, |
|
| 49 | - 71 => 1, |
|
| 50 | - ]; |
|
| 51 | - }//end if |
|
| 18 | + /** |
|
| 19 | + * Returns the lines where errors should occur. |
|
| 20 | + * |
|
| 21 | + * The key of the array should represent the line number and the value |
|
| 22 | + * should represent the number of errors that should occur on that line. |
|
| 23 | + * |
|
| 24 | + * @param string $testFile The name of the file being tested. |
|
| 25 | + * |
|
| 26 | + * @return array<int, int> |
|
| 27 | + */ |
|
| 28 | + public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc') |
|
| 29 | + { |
|
| 30 | + if ($testFile === 'FunctionCallSignatureUnitTest.js') { |
|
| 31 | + return [ |
|
| 32 | + 5 => 1, |
|
| 33 | + 6 => 2, |
|
| 34 | + 7 => 1, |
|
| 35 | + 8 => 1, |
|
| 36 | + 9 => 2, |
|
| 37 | + 10 => 3, |
|
| 38 | + 17 => 1, |
|
| 39 | + 18 => 1, |
|
| 40 | + 21 => 1, |
|
| 41 | + 24 => 1, |
|
| 42 | + 28 => 2, |
|
| 43 | + 30 => 2, |
|
| 44 | + 35 => 1, |
|
| 45 | + 49 => 1, |
|
| 46 | + 51 => 1, |
|
| 47 | + 54 => 1, |
|
| 48 | + 70 => 1, |
|
| 49 | + 71 => 1, |
|
| 50 | + ]; |
|
| 51 | + }//end if |
|
| 52 | 52 | |
| 53 | - return [ |
|
| 54 | - 5 => 1, |
|
| 55 | - 6 => 2, |
|
| 56 | - 7 => 1, |
|
| 57 | - 8 => 1, |
|
| 58 | - 9 => 2, |
|
| 59 | - 10 => 3, |
|
| 60 | - 17 => 1, |
|
| 61 | - 18 => 1, |
|
| 62 | - 31 => 1, |
|
| 63 | - 34 => 1, |
|
| 64 | - 43 => 2, |
|
| 65 | - 57 => 1, |
|
| 66 | - 59 => 1, |
|
| 67 | - 63 => 1, |
|
| 68 | - 64 => 1, |
|
| 69 | - 82 => 1, |
|
| 70 | - 93 => 1, |
|
| 71 | - 100 => 1, |
|
| 72 | - 106 => 2, |
|
| 73 | - 119 => 1, |
|
| 74 | - 120 => 1, |
|
| 75 | - 129 => 1, |
|
| 76 | - 137 => 1, |
|
| 77 | - 142 => 2, |
|
| 78 | - 171 => 1, |
|
| 79 | - 180 => 1, |
|
| 80 | - 181 => 1, |
|
| 81 | - 194 => 1, |
|
| 82 | - 213 => 2, |
|
| 83 | - 215 => 2, |
|
| 84 | - 217 => 2, |
|
| 85 | - 218 => 2, |
|
| 86 | - 277 => 1, |
|
| 87 | - 278 => 1, |
|
| 88 | - 303 => 1, |
|
| 89 | - 308 => 1, |
|
| 90 | - 321 => 1, |
|
| 91 | - 322 => 1, |
|
| 92 | - 329 => 1, |
|
| 93 | - 330 => 1, |
|
| 94 | - 337 => 1, |
|
| 95 | - 342 => 1, |
|
| 96 | - 343 => 1, |
|
| 97 | - 345 => 1, |
|
| 98 | - 346 => 2, |
|
| 99 | - 353 => 1, |
|
| 100 | - 354 => 1, |
|
| 101 | - 355 => 2, |
|
| 102 | - 377 => 1, |
|
| 103 | - 378 => 1, |
|
| 104 | - 379 => 1, |
|
| 105 | - 380 => 1, |
|
| 106 | - 385 => 1, |
|
| 107 | - 386 => 1, |
|
| 108 | - 387 => 1, |
|
| 109 | - 388 => 1, |
|
| 110 | - 393 => 1, |
|
| 111 | - 394 => 1, |
|
| 112 | - 395 => 1, |
|
| 113 | - 396 => 1, |
|
| 114 | - 411 => 1, |
|
| 115 | - 422 => 1, |
|
| 116 | - 424 => 1, |
|
| 117 | - 429 => 1, |
|
| 118 | - 432 => 1, |
|
| 119 | - 440 => 1, |
|
| 120 | - 441 => 1, |
|
| 121 | - 442 => 1, |
|
| 122 | - 464 => 1, |
|
| 123 | - 510 => 1, |
|
| 124 | - 513 => 1, |
|
| 125 | - 514 => 1, |
|
| 126 | - 523 => 1, |
|
| 127 | - 524 => 3, |
|
| 128 | - 527 => 2, |
|
| 129 | - 539 => 1, |
|
| 130 | - 540 => 1, |
|
| 131 | - 546 => 1, |
|
| 132 | - 547 => 1, |
|
| 133 | - 548 => 1, |
|
| 134 | - ]; |
|
| 53 | + return [ |
|
| 54 | + 5 => 1, |
|
| 55 | + 6 => 2, |
|
| 56 | + 7 => 1, |
|
| 57 | + 8 => 1, |
|
| 58 | + 9 => 2, |
|
| 59 | + 10 => 3, |
|
| 60 | + 17 => 1, |
|
| 61 | + 18 => 1, |
|
| 62 | + 31 => 1, |
|
| 63 | + 34 => 1, |
|
| 64 | + 43 => 2, |
|
| 65 | + 57 => 1, |
|
| 66 | + 59 => 1, |
|
| 67 | + 63 => 1, |
|
| 68 | + 64 => 1, |
|
| 69 | + 82 => 1, |
|
| 70 | + 93 => 1, |
|
| 71 | + 100 => 1, |
|
| 72 | + 106 => 2, |
|
| 73 | + 119 => 1, |
|
| 74 | + 120 => 1, |
|
| 75 | + 129 => 1, |
|
| 76 | + 137 => 1, |
|
| 77 | + 142 => 2, |
|
| 78 | + 171 => 1, |
|
| 79 | + 180 => 1, |
|
| 80 | + 181 => 1, |
|
| 81 | + 194 => 1, |
|
| 82 | + 213 => 2, |
|
| 83 | + 215 => 2, |
|
| 84 | + 217 => 2, |
|
| 85 | + 218 => 2, |
|
| 86 | + 277 => 1, |
|
| 87 | + 278 => 1, |
|
| 88 | + 303 => 1, |
|
| 89 | + 308 => 1, |
|
| 90 | + 321 => 1, |
|
| 91 | + 322 => 1, |
|
| 92 | + 329 => 1, |
|
| 93 | + 330 => 1, |
|
| 94 | + 337 => 1, |
|
| 95 | + 342 => 1, |
|
| 96 | + 343 => 1, |
|
| 97 | + 345 => 1, |
|
| 98 | + 346 => 2, |
|
| 99 | + 353 => 1, |
|
| 100 | + 354 => 1, |
|
| 101 | + 355 => 2, |
|
| 102 | + 377 => 1, |
|
| 103 | + 378 => 1, |
|
| 104 | + 379 => 1, |
|
| 105 | + 380 => 1, |
|
| 106 | + 385 => 1, |
|
| 107 | + 386 => 1, |
|
| 108 | + 387 => 1, |
|
| 109 | + 388 => 1, |
|
| 110 | + 393 => 1, |
|
| 111 | + 394 => 1, |
|
| 112 | + 395 => 1, |
|
| 113 | + 396 => 1, |
|
| 114 | + 411 => 1, |
|
| 115 | + 422 => 1, |
|
| 116 | + 424 => 1, |
|
| 117 | + 429 => 1, |
|
| 118 | + 432 => 1, |
|
| 119 | + 440 => 1, |
|
| 120 | + 441 => 1, |
|
| 121 | + 442 => 1, |
|
| 122 | + 464 => 1, |
|
| 123 | + 510 => 1, |
|
| 124 | + 513 => 1, |
|
| 125 | + 514 => 1, |
|
| 126 | + 523 => 1, |
|
| 127 | + 524 => 3, |
|
| 128 | + 527 => 2, |
|
| 129 | + 539 => 1, |
|
| 130 | + 540 => 1, |
|
| 131 | + 546 => 1, |
|
| 132 | + 547 => 1, |
|
| 133 | + 548 => 1, |
|
| 134 | + ]; |
|
| 135 | 135 | |
| 136 | - }//end getErrorList() |
|
| 136 | + }//end getErrorList() |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Returns the lines where warnings should occur. |
|
| 141 | - * |
|
| 142 | - * The key of the array should represent the line number and the value |
|
| 143 | - * should represent the number of warnings that should occur on that line. |
|
| 144 | - * |
|
| 145 | - * @return array<int, int> |
|
| 146 | - */ |
|
| 147 | - public function getWarningList() |
|
| 148 | - { |
|
| 149 | - return []; |
|
| 139 | + /** |
|
| 140 | + * Returns the lines where warnings should occur. |
|
| 141 | + * |
|
| 142 | + * The key of the array should represent the line number and the value |
|
| 143 | + * should represent the number of warnings that should occur on that line. |
|
| 144 | + * |
|
| 145 | + * @return array<int, int> |
|
| 146 | + */ |
|
| 147 | + public function getWarningList() |
|
| 148 | + { |
|
| 149 | + return []; |
|
| 150 | 150 | |
| 151 | - }//end getWarningList() |
|
| 151 | + }//end getWarningList() |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | 154 | }//end class |
@@ -10,9 +10,9 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | function test() |
| 12 | 12 | { |
| 13 | - // Some code goes here. |
|
| 13 | + // Some code goes here. |
|
| 14 | 14 | |
| 15 | - # This comment is banned. |
|
| 15 | + # This comment is banned. |
|
| 16 | 16 | |
| 17 | 17 | }//end test() |
| 18 | 18 | |
@@ -15,41 +15,41 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the lines where errors should occur. |
|
| 20 | - * |
|
| 21 | - * The key of the array should represent the line number and the value |
|
| 22 | - * should represent the number of errors that should occur on that line. |
|
| 23 | - * |
|
| 24 | - * @return array<int, int> |
|
| 25 | - */ |
|
| 26 | - public function getErrorList() |
|
| 27 | - { |
|
| 28 | - return [ |
|
| 29 | - 15 => 1, |
|
| 30 | - 24 => 1, |
|
| 31 | - 25 => 1, |
|
| 32 | - 27 => 1, |
|
| 33 | - 28 => 1, |
|
| 34 | - 29 => 1, |
|
| 35 | - ]; |
|
| 36 | - |
|
| 37 | - }//end getErrorList() |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Returns the lines where warnings should occur. |
|
| 42 | - * |
|
| 43 | - * The key of the array should represent the line number and the value |
|
| 44 | - * should represent the number of warnings that should occur on that line. |
|
| 45 | - * |
|
| 46 | - * @return array<int, int> |
|
| 47 | - */ |
|
| 48 | - public function getWarningList() |
|
| 49 | - { |
|
| 50 | - return []; |
|
| 51 | - |
|
| 52 | - }//end getWarningList() |
|
| 18 | + /** |
|
| 19 | + * Returns the lines where errors should occur. |
|
| 20 | + * |
|
| 21 | + * The key of the array should represent the line number and the value |
|
| 22 | + * should represent the number of errors that should occur on that line. |
|
| 23 | + * |
|
| 24 | + * @return array<int, int> |
|
| 25 | + */ |
|
| 26 | + public function getErrorList() |
|
| 27 | + { |
|
| 28 | + return [ |
|
| 29 | + 15 => 1, |
|
| 30 | + 24 => 1, |
|
| 31 | + 25 => 1, |
|
| 32 | + 27 => 1, |
|
| 33 | + 28 => 1, |
|
| 34 | + 29 => 1, |
|
| 35 | + ]; |
|
| 36 | + |
|
| 37 | + }//end getErrorList() |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Returns the lines where warnings should occur. |
|
| 42 | + * |
|
| 43 | + * The key of the array should represent the line number and the value |
|
| 44 | + * should represent the number of warnings that should occur on that line. |
|
| 45 | + * |
|
| 46 | + * @return array<int, int> |
|
| 47 | + */ |
|
| 48 | + public function getWarningList() |
|
| 49 | + { |
|
| 50 | + return []; |
|
| 51 | + |
|
| 52 | + }//end getWarningList() |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | }//end class |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * @return |
| 15 | 15 | * @throws |
| 16 | 16 | */ |
| 17 | - private function _functionCall($stackPtr, $depth=1, $index) |
|
| 17 | + private function _functionCall($stackPtr, $depth = 1, $index) |
|
| 18 | 18 | { |
| 19 | 19 | return $stackPtr; |
| 20 | 20 | |
@@ -2,148 +2,148 @@ discard block |
||
| 2 | 2 | class PHP_CodeSniffer_File |
| 3 | 3 | { |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * A simple function comment. |
|
| 7 | - * |
|
| 8 | - * long desc here |
|
| 9 | - * |
|
| 10 | - * @param int $stackPtr The position in @ @unknown the stack of the token |
|
| 11 | - * that opened the scope |
|
| 12 | - * @param int $detph How many scope levels down we are. |
|
| 13 | - * @param int $index The index |
|
| 14 | - * @return |
|
| 15 | - * @throws |
|
| 16 | - */ |
|
| 17 | - private function _functionCall($stackPtr, $depth=1, $index) |
|
| 18 | - { |
|
| 19 | - return $stackPtr; |
|
| 20 | - |
|
| 21 | - }//end _functionCall() |
|
| 22 | - |
|
| 23 | - // |
|
| 24 | - // Sample function comment |
|
| 25 | - // |
|
| 26 | - // |
|
| 27 | - // |
|
| 28 | - public function invalidCommentStyle() |
|
| 29 | - { |
|
| 30 | - |
|
| 31 | - }//end invalidCommentStyle() |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * |
|
| 37 | - * A simple function comment |
|
| 38 | - * |
|
| 39 | - * |
|
| 40 | - * Long description with extra blank line before and after |
|
| 41 | - * |
|
| 42 | - * |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function extraDescriptionNewlines() |
|
| 46 | - { |
|
| 47 | - |
|
| 48 | - }//end extraDescriptionNewlines() |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * A simple function comment |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function missingNewlinesBeforeTags() |
|
| 56 | - { |
|
| 57 | - |
|
| 58 | - }//end missingNewlinesBeforeTags() |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Access tag should not be treated as a long description |
|
| 63 | - * |
|
| 64 | - * @access public |
|
| 65 | - * @return void |
|
| 66 | - */ |
|
| 67 | - public function accessTag() |
|
| 68 | - { |
|
| 69 | - |
|
| 70 | - }//end accessTag() |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Constructor |
|
| 74 | - * |
|
| 75 | - * No return tag |
|
| 76 | - */ |
|
| 77 | - function PHP_CodeSniffer_File() |
|
| 78 | - { |
|
| 79 | - return; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Destructor |
|
| 85 | - * |
|
| 86 | - * No return tag too |
|
| 87 | - */ |
|
| 88 | - function _PHP_CodeSniffer_File() |
|
| 89 | - { |
|
| 90 | - return; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Destructor PHP5 |
|
| 96 | - */ |
|
| 97 | - function __destruct() |
|
| 98 | - { |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - function missingComment() |
|
| 104 | - { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * no return tag |
|
| 111 | - * |
|
| 112 | - */ |
|
| 113 | - public function noReturn($one) |
|
| 114 | - { |
|
| 115 | - |
|
| 116 | - }//end noReturn() |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Param not immediate |
|
| 121 | - * |
|
| 122 | - * @return |
|
| 123 | - * @param int $threeSpaces |
|
| 124 | - * @param int $superfluous |
|
| 125 | - * @param missing |
|
| 126 | - * @param |
|
| 127 | - */ |
|
| 128 | - public function missingDescription($threeSpaces) |
|
| 129 | - { |
|
| 130 | - |
|
| 131 | - }//end missingDescription() |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Param not immediate |
|
| 136 | - * |
|
| 137 | - * @param int $one comment |
|
| 138 | - * @param int $two comment |
|
| 139 | - * @param string $three comment |
|
| 140 | - * |
|
| 141 | - * @return void |
|
| 142 | - */ |
|
| 143 | - public function oneSpaceAfterLongestVar($one, $two, $three) |
|
| 144 | - { |
|
| 145 | - |
|
| 146 | - }//end oneSpaceAfterLongestVar() |
|
| 5 | + /** |
|
| 6 | + * A simple function comment. |
|
| 7 | + * |
|
| 8 | + * long desc here |
|
| 9 | + * |
|
| 10 | + * @param int $stackPtr The position in @ @unknown the stack of the token |
|
| 11 | + * that opened the scope |
|
| 12 | + * @param int $detph How many scope levels down we are. |
|
| 13 | + * @param int $index The index |
|
| 14 | + * @return |
|
| 15 | + * @throws |
|
| 16 | + */ |
|
| 17 | + private function _functionCall($stackPtr, $depth=1, $index) |
|
| 18 | + { |
|
| 19 | + return $stackPtr; |
|
| 20 | + |
|
| 21 | + }//end _functionCall() |
|
| 22 | + |
|
| 23 | + // |
|
| 24 | + // Sample function comment |
|
| 25 | + // |
|
| 26 | + // |
|
| 27 | + // |
|
| 28 | + public function invalidCommentStyle() |
|
| 29 | + { |
|
| 30 | + |
|
| 31 | + }//end invalidCommentStyle() |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * |
|
| 37 | + * A simple function comment |
|
| 38 | + * |
|
| 39 | + * |
|
| 40 | + * Long description with extra blank line before and after |
|
| 41 | + * |
|
| 42 | + * |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function extraDescriptionNewlines() |
|
| 46 | + { |
|
| 47 | + |
|
| 48 | + }//end extraDescriptionNewlines() |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * A simple function comment |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function missingNewlinesBeforeTags() |
|
| 56 | + { |
|
| 57 | + |
|
| 58 | + }//end missingNewlinesBeforeTags() |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Access tag should not be treated as a long description |
|
| 63 | + * |
|
| 64 | + * @access public |
|
| 65 | + * @return void |
|
| 66 | + */ |
|
| 67 | + public function accessTag() |
|
| 68 | + { |
|
| 69 | + |
|
| 70 | + }//end accessTag() |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Constructor |
|
| 74 | + * |
|
| 75 | + * No return tag |
|
| 76 | + */ |
|
| 77 | + function PHP_CodeSniffer_File() |
|
| 78 | + { |
|
| 79 | + return; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Destructor |
|
| 85 | + * |
|
| 86 | + * No return tag too |
|
| 87 | + */ |
|
| 88 | + function _PHP_CodeSniffer_File() |
|
| 89 | + { |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Destructor PHP5 |
|
| 96 | + */ |
|
| 97 | + function __destruct() |
|
| 98 | + { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + function missingComment() |
|
| 104 | + { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * no return tag |
|
| 111 | + * |
|
| 112 | + */ |
|
| 113 | + public function noReturn($one) |
|
| 114 | + { |
|
| 115 | + |
|
| 116 | + }//end noReturn() |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Param not immediate |
|
| 121 | + * |
|
| 122 | + * @return |
|
| 123 | + * @param int $threeSpaces |
|
| 124 | + * @param int $superfluous |
|
| 125 | + * @param missing |
|
| 126 | + * @param |
|
| 127 | + */ |
|
| 128 | + public function missingDescription($threeSpaces) |
|
| 129 | + { |
|
| 130 | + |
|
| 131 | + }//end missingDescription() |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Param not immediate |
|
| 136 | + * |
|
| 137 | + * @param int $one comment |
|
| 138 | + * @param int $two comment |
|
| 139 | + * @param string $three comment |
|
| 140 | + * |
|
| 141 | + * @return void |
|
| 142 | + */ |
|
| 143 | + public function oneSpaceAfterLongestVar($one, $two, $three) |
|
| 144 | + { |
|
| 145 | + |
|
| 146 | + }//end oneSpaceAfterLongestVar() |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | 149 | }//end class |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function functionOutsideClass(&$str, &$foo) |
| 161 | 161 | { |
| 162 | - return; |
|
| 162 | + return; |
|
| 163 | 163 | }//end functionOutsideClass() |
| 164 | 164 | |
| 165 | 165 | function missingCommentOutsideClass() |
| 166 | 166 | { |
| 167 | - return; |
|
| 167 | + return; |
|
| 168 | 168 | }//end missingCommentOutsideClass() |
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | ?><?php |
| 172 | 172 | function tagBeforeComment() |
| 173 | 173 | { |
| 174 | - return; |
|
| 174 | + return; |
|
| 175 | 175 | }//end tagBeforeComment() |
| 176 | 176 | |
| 177 | 177 | |
@@ -244,12 +244,12 @@ discard block |
||
| 244 | 244 | function myFunction() {} |
| 245 | 245 | |
| 246 | 246 | abstract class MyClass { |
| 247 | - /** |
|
| 248 | - * An abstract function. |
|
| 249 | - * |
|
| 250 | - * @return string[] |
|
| 251 | - */ |
|
| 252 | - abstract protected function myFunction(); |
|
| 247 | + /** |
|
| 248 | + * An abstract function. |
|
| 249 | + * |
|
| 250 | + * @return string[] |
|
| 251 | + */ |
|
| 252 | + abstract protected function myFunction(); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -271,18 +271,18 @@ discard block |
||
| 271 | 271 | * |
| 272 | 272 | */ |
| 273 | 273 | function _() { |
| 274 | - return $foo; |
|
| 274 | + return $foo; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | class Baz { |
| 278 | - /** |
|
| 279 | - * The PHP5 constructor |
|
| 280 | - * |
|
| 281 | - * No return tag |
|
| 282 | - */ |
|
| 283 | - public function __construct() { |
|
| 284 | - |
|
| 285 | - } |
|
| 278 | + /** |
|
| 279 | + * The PHP5 constructor |
|
| 280 | + * |
|
| 281 | + * No return tag |
|
| 282 | + */ |
|
| 283 | + public function __construct() { |
|
| 284 | + |
|
| 285 | + } |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return void |
| 296 | 296 | */ |
| 297 | 297 | function completeStep($status, array $array = [Class1::class, 'test'], $note = '') { |
| 298 | - echo 'foo'; |
|
| 298 | + echo 'foo'; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -379,45 +379,45 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function setTranslator($a, &$b): void |
| 381 | 381 | { |
| 382 | - $this->translator = $translator; |
|
| 382 | + $this->translator = $translator; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | // phpcs:set PEAR.Commenting.FunctionComment minimumVisibility protected |
| 386 | 386 | private function setTranslator2($a, &$b): void |
| 387 | 387 | { |
| 388 | - $this->translator = $translator; |
|
| 388 | + $this->translator = $translator; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | // phpcs:set PEAR.Commenting.FunctionComment minimumVisibility public |
| 392 | 392 | protected function setTranslator3($a, &$b): void |
| 393 | 393 | { |
| 394 | - $this->translator = $translator; |
|
| 394 | + $this->translator = $translator; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | private function setTranslator4($a, &$b): void |
| 398 | 398 | { |
| 399 | - $this->translator = $translator; |
|
| 399 | + $this->translator = $translator; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | class Bar { |
| 403 | - /** |
|
| 404 | - * The PHP5 constructor |
|
| 405 | - * |
|
| 406 | - * @return |
|
| 407 | - */ |
|
| 408 | - public function __construct() { |
|
| 409 | - |
|
| 410 | - } |
|
| 403 | + /** |
|
| 404 | + * The PHP5 constructor |
|
| 405 | + * |
|
| 406 | + * @return |
|
| 407 | + */ |
|
| 408 | + public function __construct() { |
|
| 409 | + |
|
| 410 | + } |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] |
| 414 | 414 | class Bar { |
| 415 | - /** |
|
| 416 | - * The PHP5 constructor |
|
| 417 | - */ |
|
| 418 | - public function __construct() { |
|
| 415 | + /** |
|
| 416 | + * The PHP5 constructor |
|
| 417 | + */ |
|
| 418 | + public function __construct() { |
|
| 419 | 419 | |
| 420 | - } |
|
| 420 | + } |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] ignored |
@@ -431,48 +431,48 @@ discard block |
||
| 431 | 431 | // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] __construct,__destruct |
| 432 | 432 | |
| 433 | 433 | class Something implements JsonSerializable { |
| 434 | - /** |
|
| 435 | - * Single attribute. |
|
| 436 | - * |
|
| 437 | - * @return mixed |
|
| 438 | - */ |
|
| 439 | - #[ReturnTypeWillChange] |
|
| 440 | - public function jsonSerialize() {} |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Multiple attributes. |
|
| 444 | - * |
|
| 445 | - * @return Something |
|
| 446 | - */ |
|
| 447 | - #[AttributeA] |
|
| 448 | - #[AttributeB] |
|
| 449 | - public function methodName() {} |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Blank line between docblock and attribute. |
|
| 453 | - * |
|
| 454 | - * @return mixed |
|
| 455 | - */ |
|
| 456 | - |
|
| 457 | - #[ReturnTypeWillChange] |
|
| 458 | - public function blankLineDetectionA() {} |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Blank line between attribute and function declaration. |
|
| 462 | - * |
|
| 463 | - * @return mixed |
|
| 464 | - */ |
|
| 465 | - #[ReturnTypeWillChange] |
|
| 466 | - |
|
| 467 | - public function blankLineDetectionB() {} |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Blank line between both docblock and attribute and attribute and function declaration. |
|
| 471 | - * |
|
| 472 | - * @return mixed |
|
| 473 | - */ |
|
| 474 | - |
|
| 475 | - #[ReturnTypeWillChange] |
|
| 476 | - |
|
| 477 | - public function blankLineDetectionC() {} |
|
| 434 | + /** |
|
| 435 | + * Single attribute. |
|
| 436 | + * |
|
| 437 | + * @return mixed |
|
| 438 | + */ |
|
| 439 | + #[ReturnTypeWillChange] |
|
| 440 | + public function jsonSerialize() {} |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Multiple attributes. |
|
| 444 | + * |
|
| 445 | + * @return Something |
|
| 446 | + */ |
|
| 447 | + #[AttributeA] |
|
| 448 | + #[AttributeB] |
|
| 449 | + public function methodName() {} |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Blank line between docblock and attribute. |
|
| 453 | + * |
|
| 454 | + * @return mixed |
|
| 455 | + */ |
|
| 456 | + |
|
| 457 | + #[ReturnTypeWillChange] |
|
| 458 | + public function blankLineDetectionA() {} |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Blank line between attribute and function declaration. |
|
| 462 | + * |
|
| 463 | + * @return mixed |
|
| 464 | + */ |
|
| 465 | + #[ReturnTypeWillChange] |
|
| 466 | + |
|
| 467 | + public function blankLineDetectionB() {} |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Blank line between both docblock and attribute and attribute and function declaration. |
|
| 471 | + * |
|
| 472 | + * @return mixed |
|
| 473 | + */ |
|
| 474 | + |
|
| 475 | + #[ReturnTypeWillChange] |
|
| 476 | + |
|
| 477 | + public function blankLineDetectionC() {} |
|
| 478 | 478 | } |
@@ -16,164 +16,164 @@ |
||
| 16 | 16 | class ScopeClosingBraceSniff implements Sniff |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The number of spaces code should be indented. |
|
| 21 | - * |
|
| 22 | - * @var integer |
|
| 23 | - */ |
|
| 24 | - public $indent = 4; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Returns an array of tokens this test wants to listen for. |
|
| 29 | - * |
|
| 30 | - * @return int[] |
|
| 31 | - */ |
|
| 32 | - public function register() |
|
| 33 | - { |
|
| 34 | - return Tokens::$scopeOpeners; |
|
| 35 | - |
|
| 36 | - }//end register() |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes this test, when one of its tokens is encountered. |
|
| 41 | - * |
|
| 42 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document. |
|
| 43 | - * @param int $stackPtr The position of the current token |
|
| 44 | - * in the stack passed in $tokens. |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public function process(File $phpcsFile, $stackPtr) |
|
| 49 | - { |
|
| 50 | - $tokens = $phpcsFile->getTokens(); |
|
| 51 | - |
|
| 52 | - // If this is an inline condition (ie. there is no scope opener), then |
|
| 53 | - // return, as this is not a new scope. |
|
| 54 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
| 55 | - return; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $scopeStart = $tokens[$stackPtr]['scope_opener']; |
|
| 59 | - $scopeEnd = $tokens[$stackPtr]['scope_closer']; |
|
| 60 | - |
|
| 61 | - // If the scope closer doesn't think it belongs to this scope opener |
|
| 62 | - // then the opener is sharing its closer with other tokens. We only |
|
| 63 | - // want to process the closer once, so skip this one. |
|
| 64 | - if (isset($tokens[$scopeEnd]['scope_condition']) === false |
|
| 65 | - || $tokens[$scopeEnd]['scope_condition'] !== $stackPtr |
|
| 66 | - ) { |
|
| 67 | - return; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // We need to actually find the first piece of content on this line, |
|
| 71 | - // because if this is a method with tokens before it (public, static etc) |
|
| 72 | - // or an if with an else before it, then we need to start the scope |
|
| 73 | - // checking from there, rather than the current token. |
|
| 74 | - $lineStart = ($stackPtr - 1); |
|
| 75 | - for ($lineStart; $lineStart > 0; $lineStart--) { |
|
| 76 | - if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) { |
|
| 77 | - break; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $lineStart++; |
|
| 82 | - |
|
| 83 | - $startColumn = 1; |
|
| 84 | - if ($tokens[$lineStart]['code'] === T_WHITESPACE) { |
|
| 85 | - $startColumn = $tokens[($lineStart + 1)]['column']; |
|
| 86 | - } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) { |
|
| 87 | - $trimmed = ltrim($tokens[$lineStart]['content']); |
|
| 88 | - if ($trimmed === '') { |
|
| 89 | - $startColumn = $tokens[($lineStart + 1)]['column']; |
|
| 90 | - } else { |
|
| 91 | - $startColumn = (strlen($tokens[$lineStart]['content']) - strlen($trimmed)); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Check that the closing brace is on it's own line. |
|
| 96 | - $lastContent = $phpcsFile->findPrevious( |
|
| 97 | - [ |
|
| 98 | - T_WHITESPACE, |
|
| 99 | - T_INLINE_HTML, |
|
| 100 | - T_OPEN_TAG, |
|
| 101 | - ], |
|
| 102 | - ($scopeEnd - 1), |
|
| 103 | - $scopeStart, |
|
| 104 | - true |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { |
|
| 108 | - $error = 'Closing brace must be on a line by itself'; |
|
| 109 | - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Line'); |
|
| 110 | - if ($fix === true) { |
|
| 111 | - $phpcsFile->fixer->addNewlineBefore($scopeEnd); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Check now that the closing brace is lined up correctly. |
|
| 118 | - $lineStart = ($scopeEnd - 1); |
|
| 119 | - for ($lineStart; $lineStart > 0; $lineStart--) { |
|
| 120 | - if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) { |
|
| 121 | - break; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $lineStart++; |
|
| 126 | - |
|
| 127 | - $braceIndent = 0; |
|
| 128 | - if ($tokens[$lineStart]['code'] === T_WHITESPACE) { |
|
| 129 | - $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1); |
|
| 130 | - } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) { |
|
| 131 | - $trimmed = ltrim($tokens[$lineStart]['content']); |
|
| 132 | - if ($trimmed === '') { |
|
| 133 | - $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1); |
|
| 134 | - } else { |
|
| 135 | - $braceIndent = (strlen($tokens[$lineStart]['content']) - strlen($trimmed) - 1); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $fix = false; |
|
| 140 | - if ($tokens[$stackPtr]['code'] === T_CASE |
|
| 141 | - || $tokens[$stackPtr]['code'] === T_DEFAULT |
|
| 142 | - ) { |
|
| 143 | - // BREAK statements should be indented n spaces from the |
|
| 144 | - // CASE or DEFAULT statement. |
|
| 145 | - $expectedIndent = ($startColumn + $this->indent - 1); |
|
| 146 | - if ($braceIndent !== $expectedIndent) { |
|
| 147 | - $error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s'; |
|
| 148 | - $data = [ |
|
| 149 | - $expectedIndent, |
|
| 150 | - $braceIndent, |
|
| 151 | - ]; |
|
| 152 | - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data); |
|
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - $expectedIndent = max(0, ($startColumn - 1)); |
|
| 156 | - if ($braceIndent !== $expectedIndent) { |
|
| 157 | - $error = 'Closing brace indented incorrectly; expected %s spaces, found %s'; |
|
| 158 | - $data = [ |
|
| 159 | - $expectedIndent, |
|
| 160 | - $braceIndent, |
|
| 161 | - ]; |
|
| 162 | - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); |
|
| 163 | - } |
|
| 164 | - }//end if |
|
| 165 | - |
|
| 166 | - if ($fix === true) { |
|
| 167 | - $spaces = str_repeat(' ', $expectedIndent); |
|
| 168 | - if ($braceIndent === 0) { |
|
| 169 | - $phpcsFile->fixer->addContentBefore($lineStart, $spaces); |
|
| 170 | - } else { |
|
| 171 | - $phpcsFile->fixer->replaceToken($lineStart, ltrim($tokens[$lineStart]['content'])); |
|
| 172 | - $phpcsFile->fixer->addContentBefore($lineStart, $spaces); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - }//end process() |
|
| 19 | + /** |
|
| 20 | + * The number of spaces code should be indented. |
|
| 21 | + * |
|
| 22 | + * @var integer |
|
| 23 | + */ |
|
| 24 | + public $indent = 4; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Returns an array of tokens this test wants to listen for. |
|
| 29 | + * |
|
| 30 | + * @return int[] |
|
| 31 | + */ |
|
| 32 | + public function register() |
|
| 33 | + { |
|
| 34 | + return Tokens::$scopeOpeners; |
|
| 35 | + |
|
| 36 | + }//end register() |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes this test, when one of its tokens is encountered. |
|
| 41 | + * |
|
| 42 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document. |
|
| 43 | + * @param int $stackPtr The position of the current token |
|
| 44 | + * in the stack passed in $tokens. |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public function process(File $phpcsFile, $stackPtr) |
|
| 49 | + { |
|
| 50 | + $tokens = $phpcsFile->getTokens(); |
|
| 51 | + |
|
| 52 | + // If this is an inline condition (ie. there is no scope opener), then |
|
| 53 | + // return, as this is not a new scope. |
|
| 54 | + if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $scopeStart = $tokens[$stackPtr]['scope_opener']; |
|
| 59 | + $scopeEnd = $tokens[$stackPtr]['scope_closer']; |
|
| 60 | + |
|
| 61 | + // If the scope closer doesn't think it belongs to this scope opener |
|
| 62 | + // then the opener is sharing its closer with other tokens. We only |
|
| 63 | + // want to process the closer once, so skip this one. |
|
| 64 | + if (isset($tokens[$scopeEnd]['scope_condition']) === false |
|
| 65 | + || $tokens[$scopeEnd]['scope_condition'] !== $stackPtr |
|
| 66 | + ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // We need to actually find the first piece of content on this line, |
|
| 71 | + // because if this is a method with tokens before it (public, static etc) |
|
| 72 | + // or an if with an else before it, then we need to start the scope |
|
| 73 | + // checking from there, rather than the current token. |
|
| 74 | + $lineStart = ($stackPtr - 1); |
|
| 75 | + for ($lineStart; $lineStart > 0; $lineStart--) { |
|
| 76 | + if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) { |
|
| 77 | + break; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $lineStart++; |
|
| 82 | + |
|
| 83 | + $startColumn = 1; |
|
| 84 | + if ($tokens[$lineStart]['code'] === T_WHITESPACE) { |
|
| 85 | + $startColumn = $tokens[($lineStart + 1)]['column']; |
|
| 86 | + } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) { |
|
| 87 | + $trimmed = ltrim($tokens[$lineStart]['content']); |
|
| 88 | + if ($trimmed === '') { |
|
| 89 | + $startColumn = $tokens[($lineStart + 1)]['column']; |
|
| 90 | + } else { |
|
| 91 | + $startColumn = (strlen($tokens[$lineStart]['content']) - strlen($trimmed)); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Check that the closing brace is on it's own line. |
|
| 96 | + $lastContent = $phpcsFile->findPrevious( |
|
| 97 | + [ |
|
| 98 | + T_WHITESPACE, |
|
| 99 | + T_INLINE_HTML, |
|
| 100 | + T_OPEN_TAG, |
|
| 101 | + ], |
|
| 102 | + ($scopeEnd - 1), |
|
| 103 | + $scopeStart, |
|
| 104 | + true |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { |
|
| 108 | + $error = 'Closing brace must be on a line by itself'; |
|
| 109 | + $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Line'); |
|
| 110 | + if ($fix === true) { |
|
| 111 | + $phpcsFile->fixer->addNewlineBefore($scopeEnd); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Check now that the closing brace is lined up correctly. |
|
| 118 | + $lineStart = ($scopeEnd - 1); |
|
| 119 | + for ($lineStart; $lineStart > 0; $lineStart--) { |
|
| 120 | + if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) { |
|
| 121 | + break; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $lineStart++; |
|
| 126 | + |
|
| 127 | + $braceIndent = 0; |
|
| 128 | + if ($tokens[$lineStart]['code'] === T_WHITESPACE) { |
|
| 129 | + $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1); |
|
| 130 | + } else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) { |
|
| 131 | + $trimmed = ltrim($tokens[$lineStart]['content']); |
|
| 132 | + if ($trimmed === '') { |
|
| 133 | + $braceIndent = ($tokens[($lineStart + 1)]['column'] - 1); |
|
| 134 | + } else { |
|
| 135 | + $braceIndent = (strlen($tokens[$lineStart]['content']) - strlen($trimmed) - 1); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $fix = false; |
|
| 140 | + if ($tokens[$stackPtr]['code'] === T_CASE |
|
| 141 | + || $tokens[$stackPtr]['code'] === T_DEFAULT |
|
| 142 | + ) { |
|
| 143 | + // BREAK statements should be indented n spaces from the |
|
| 144 | + // CASE or DEFAULT statement. |
|
| 145 | + $expectedIndent = ($startColumn + $this->indent - 1); |
|
| 146 | + if ($braceIndent !== $expectedIndent) { |
|
| 147 | + $error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s'; |
|
| 148 | + $data = [ |
|
| 149 | + $expectedIndent, |
|
| 150 | + $braceIndent, |
|
| 151 | + ]; |
|
| 152 | + $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data); |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + $expectedIndent = max(0, ($startColumn - 1)); |
|
| 156 | + if ($braceIndent !== $expectedIndent) { |
|
| 157 | + $error = 'Closing brace indented incorrectly; expected %s spaces, found %s'; |
|
| 158 | + $data = [ |
|
| 159 | + $expectedIndent, |
|
| 160 | + $braceIndent, |
|
| 161 | + ]; |
|
| 162 | + $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); |
|
| 163 | + } |
|
| 164 | + }//end if |
|
| 165 | + |
|
| 166 | + if ($fix === true) { |
|
| 167 | + $spaces = str_repeat(' ', $expectedIndent); |
|
| 168 | + if ($braceIndent === 0) { |
|
| 169 | + $phpcsFile->fixer->addContentBefore($lineStart, $spaces); |
|
| 170 | + } else { |
|
| 171 | + $phpcsFile->fixer->replaceToken($lineStart, ltrim($tokens[$lineStart]['content'])); |
|
| 172 | + $phpcsFile->fixer->addContentBefore($lineStart, $spaces); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + }//end process() |
|
| 177 | 177 | |
| 178 | 178 | |
| 179 | 179 | }//end class |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $expectedIndent, |
| 150 | 150 | $braceIndent, |
| 151 | 151 | ]; |
| 152 | - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data); |
|
| 152 | + $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data); |
|
| 153 | 153 | } |
| 154 | 154 | } else { |
| 155 | 155 | $expectedIndent = max(0, ($startColumn - 1)); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $expectedIndent, |
| 160 | 160 | $braceIndent, |
| 161 | 161 | ]; |
| 162 | - $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); |
|
| 162 | + $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data); |
|
| 163 | 163 | } |
| 164 | 164 | }//end if |
| 165 | 165 | |
@@ -14,11 +14,11 @@ |
||
| 14 | 14 | class ScopeIndentSniff extends GenericScopeIndentSniff |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Any scope openers that should not cause an indent. |
|
| 19 | - * |
|
| 20 | - * @var int[] |
|
| 21 | - */ |
|
| 22 | - protected $nonIndentingScopes = [T_SWITCH]; |
|
| 17 | + /** |
|
| 18 | + * Any scope openers that should not cause an indent. |
|
| 19 | + * |
|
| 20 | + * @var int[] |
|
| 21 | + */ |
|
| 22 | + protected $nonIndentingScopes = [T_SWITCH]; |
|
| 23 | 23 | |
| 24 | 24 | }//end class |
@@ -19,118 +19,118 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Returns an array of tokens this test wants to listen for. |
|
| 24 | - * |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - public function register() |
|
| 28 | - { |
|
| 29 | - return [ |
|
| 30 | - T_INCLUDE_ONCE, |
|
| 31 | - T_REQUIRE_ONCE, |
|
| 32 | - T_REQUIRE, |
|
| 33 | - T_INCLUDE, |
|
| 34 | - ]; |
|
| 35 | - |
|
| 36 | - }//end register() |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes this test, when one of its tokens is encountered. |
|
| 41 | - * |
|
| 42 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 43 | - * @param int $stackPtr The position of the current token in the |
|
| 44 | - * stack passed in $tokens. |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public function process(File $phpcsFile, $stackPtr) |
|
| 49 | - { |
|
| 50 | - $tokens = $phpcsFile->getTokens(); |
|
| 51 | - |
|
| 52 | - $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
| 53 | - if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) { |
|
| 54 | - $error = '"%s" is a statement not a function; no parentheses are required'; |
|
| 55 | - $data = [$tokens[$stackPtr]['content']]; |
|
| 56 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'BracketsNotRequired', $data); |
|
| 57 | - if ($fix === true) { |
|
| 58 | - $phpcsFile->fixer->beginChangeset(); |
|
| 59 | - $phpcsFile->fixer->replaceToken($tokens[$nextToken]['parenthesis_closer'], ''); |
|
| 60 | - if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) { |
|
| 61 | - $phpcsFile->fixer->replaceToken($nextToken, ' '); |
|
| 62 | - } else { |
|
| 63 | - $phpcsFile->fixer->replaceToken($nextToken, ''); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $phpcsFile->fixer->endChangeset(); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (count($tokens[$stackPtr]['conditions']) !== 0) { |
|
| 71 | - $inCondition = true; |
|
| 72 | - } else { |
|
| 73 | - $inCondition = false; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Check to see if this including statement is within the parenthesis |
|
| 77 | - // of a condition. If that's the case then we need to process it as being |
|
| 78 | - // within a condition, as they are checking the return value. |
|
| 79 | - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { |
|
| 80 | - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) { |
|
| 81 | - if (isset($tokens[$left]['parenthesis_owner']) === true) { |
|
| 82 | - $inCondition = true; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Check to see if they are assigning the return value of this |
|
| 88 | - // including call. If they are then they are probably checking it, so |
|
| 89 | - // it's conditional. |
|
| 90 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
| 91 | - if (isset(Tokens::$assignmentTokens[$tokens[$previous]['code']]) === true) { |
|
| 92 | - // The have assigned the return value to it, so its conditional. |
|
| 93 | - $inCondition = true; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $tokenCode = $tokens[$stackPtr]['code']; |
|
| 97 | - if ($inCondition === true) { |
|
| 98 | - // We are inside a conditional statement. We need an include_once. |
|
| 99 | - if ($tokenCode === T_REQUIRE_ONCE) { |
|
| 100 | - $error = 'File is being conditionally included; '; |
|
| 101 | - $error .= 'use "include_once" instead'; |
|
| 102 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseIncludeOnce'); |
|
| 103 | - if ($fix === true) { |
|
| 104 | - $phpcsFile->fixer->replaceToken($stackPtr, 'include_once'); |
|
| 105 | - } |
|
| 106 | - } else if ($tokenCode === T_REQUIRE) { |
|
| 107 | - $error = 'File is being conditionally included; '; |
|
| 108 | - $error .= 'use "include" instead'; |
|
| 109 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseInclude'); |
|
| 110 | - if ($fix === true) { |
|
| 111 | - $phpcsFile->fixer->replaceToken($stackPtr, 'include'); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } else { |
|
| 115 | - // We are unconditionally including, we need a require_once. |
|
| 116 | - if ($tokenCode === T_INCLUDE_ONCE) { |
|
| 117 | - $error = 'File is being unconditionally included; '; |
|
| 118 | - $error .= 'use "require_once" instead'; |
|
| 119 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequireOnce'); |
|
| 120 | - if ($fix === true) { |
|
| 121 | - $phpcsFile->fixer->replaceToken($stackPtr, 'require_once'); |
|
| 122 | - } |
|
| 123 | - } else if ($tokenCode === T_INCLUDE) { |
|
| 124 | - $error = 'File is being unconditionally included; '; |
|
| 125 | - $error .= 'use "require" instead'; |
|
| 126 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequire'); |
|
| 127 | - if ($fix === true) { |
|
| 128 | - $phpcsFile->fixer->replaceToken($stackPtr, 'require'); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - }//end if |
|
| 132 | - |
|
| 133 | - }//end process() |
|
| 22 | + /** |
|
| 23 | + * Returns an array of tokens this test wants to listen for. |
|
| 24 | + * |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + public function register() |
|
| 28 | + { |
|
| 29 | + return [ |
|
| 30 | + T_INCLUDE_ONCE, |
|
| 31 | + T_REQUIRE_ONCE, |
|
| 32 | + T_REQUIRE, |
|
| 33 | + T_INCLUDE, |
|
| 34 | + ]; |
|
| 35 | + |
|
| 36 | + }//end register() |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes this test, when one of its tokens is encountered. |
|
| 41 | + * |
|
| 42 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 43 | + * @param int $stackPtr The position of the current token in the |
|
| 44 | + * stack passed in $tokens. |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public function process(File $phpcsFile, $stackPtr) |
|
| 49 | + { |
|
| 50 | + $tokens = $phpcsFile->getTokens(); |
|
| 51 | + |
|
| 52 | + $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
| 53 | + if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) { |
|
| 54 | + $error = '"%s" is a statement not a function; no parentheses are required'; |
|
| 55 | + $data = [$tokens[$stackPtr]['content']]; |
|
| 56 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'BracketsNotRequired', $data); |
|
| 57 | + if ($fix === true) { |
|
| 58 | + $phpcsFile->fixer->beginChangeset(); |
|
| 59 | + $phpcsFile->fixer->replaceToken($tokens[$nextToken]['parenthesis_closer'], ''); |
|
| 60 | + if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) { |
|
| 61 | + $phpcsFile->fixer->replaceToken($nextToken, ' '); |
|
| 62 | + } else { |
|
| 63 | + $phpcsFile->fixer->replaceToken($nextToken, ''); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $phpcsFile->fixer->endChangeset(); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (count($tokens[$stackPtr]['conditions']) !== 0) { |
|
| 71 | + $inCondition = true; |
|
| 72 | + } else { |
|
| 73 | + $inCondition = false; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Check to see if this including statement is within the parenthesis |
|
| 77 | + // of a condition. If that's the case then we need to process it as being |
|
| 78 | + // within a condition, as they are checking the return value. |
|
| 79 | + if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { |
|
| 80 | + foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) { |
|
| 81 | + if (isset($tokens[$left]['parenthesis_owner']) === true) { |
|
| 82 | + $inCondition = true; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Check to see if they are assigning the return value of this |
|
| 88 | + // including call. If they are then they are probably checking it, so |
|
| 89 | + // it's conditional. |
|
| 90 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
| 91 | + if (isset(Tokens::$assignmentTokens[$tokens[$previous]['code']]) === true) { |
|
| 92 | + // The have assigned the return value to it, so its conditional. |
|
| 93 | + $inCondition = true; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $tokenCode = $tokens[$stackPtr]['code']; |
|
| 97 | + if ($inCondition === true) { |
|
| 98 | + // We are inside a conditional statement. We need an include_once. |
|
| 99 | + if ($tokenCode === T_REQUIRE_ONCE) { |
|
| 100 | + $error = 'File is being conditionally included; '; |
|
| 101 | + $error .= 'use "include_once" instead'; |
|
| 102 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseIncludeOnce'); |
|
| 103 | + if ($fix === true) { |
|
| 104 | + $phpcsFile->fixer->replaceToken($stackPtr, 'include_once'); |
|
| 105 | + } |
|
| 106 | + } else if ($tokenCode === T_REQUIRE) { |
|
| 107 | + $error = 'File is being conditionally included; '; |
|
| 108 | + $error .= 'use "include" instead'; |
|
| 109 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseInclude'); |
|
| 110 | + if ($fix === true) { |
|
| 111 | + $phpcsFile->fixer->replaceToken($stackPtr, 'include'); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } else { |
|
| 115 | + // We are unconditionally including, we need a require_once. |
|
| 116 | + if ($tokenCode === T_INCLUDE_ONCE) { |
|
| 117 | + $error = 'File is being unconditionally included; '; |
|
| 118 | + $error .= 'use "require_once" instead'; |
|
| 119 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequireOnce'); |
|
| 120 | + if ($fix === true) { |
|
| 121 | + $phpcsFile->fixer->replaceToken($stackPtr, 'require_once'); |
|
| 122 | + } |
|
| 123 | + } else if ($tokenCode === T_INCLUDE) { |
|
| 124 | + $error = 'File is being unconditionally included; '; |
|
| 125 | + $error .= 'use "require" instead'; |
|
| 126 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'UseRequire'); |
|
| 127 | + if ($fix === true) { |
|
| 128 | + $phpcsFile->fixer->replaceToken($stackPtr, 'require'); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + }//end if |
|
| 132 | + |
|
| 133 | + }//end process() |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | 136 | }//end class |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | $tokens[$stackPtr]['content'], |
| 82 | 82 | ($braceLine - $classLine - 1), |
| 83 | 83 | ]; |
| 84 | - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data); |
|
| 84 | + $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data); |
|
| 85 | 85 | if ($fix === true) { |
| 86 | 86 | $phpcsFile->fixer->beginChangeset(); |
| 87 | 87 | for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) { |
@@ -16,135 +16,135 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Returns an array of tokens this test wants to listen for. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function register() |
|
| 25 | - { |
|
| 26 | - return [ |
|
| 27 | - T_CLASS, |
|
| 28 | - T_INTERFACE, |
|
| 29 | - T_TRAIT, |
|
| 30 | - T_ENUM, |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - }//end register() |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Processes this test, when one of its tokens is encountered. |
|
| 38 | - * |
|
| 39 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 40 | - * @param integer $stackPtr The position of the current token in the |
|
| 41 | - * stack passed in $tokens. |
|
| 42 | - * |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function process(File $phpcsFile, $stackPtr) |
|
| 46 | - { |
|
| 47 | - $tokens = $phpcsFile->getTokens(); |
|
| 48 | - $errorData = [strtolower($tokens[$stackPtr]['content'])]; |
|
| 49 | - |
|
| 50 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
| 51 | - $error = 'Possible parse error: %s missing opening or closing brace'; |
|
| 52 | - $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData); |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $curlyBrace = $tokens[$stackPtr]['scope_opener']; |
|
| 57 | - $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true); |
|
| 58 | - $classLine = $tokens[$lastContent]['line']; |
|
| 59 | - $braceLine = $tokens[$curlyBrace]['line']; |
|
| 60 | - if ($braceLine === $classLine) { |
|
| 61 | - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line'); |
|
| 62 | - $error = 'Opening brace of a %s must be on the line after the definition'; |
|
| 63 | - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNewLine', $errorData); |
|
| 64 | - if ($fix === true) { |
|
| 65 | - $phpcsFile->fixer->beginChangeset(); |
|
| 66 | - if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) { |
|
| 67 | - $phpcsFile->fixer->replaceToken(($curlyBrace - 1), ''); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $phpcsFile->fixer->addNewlineBefore($curlyBrace); |
|
| 71 | - $phpcsFile->fixer->endChangeset(); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return; |
|
| 75 | - } else { |
|
| 76 | - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line'); |
|
| 77 | - |
|
| 78 | - if ($braceLine > ($classLine + 1)) { |
|
| 79 | - $error = 'Opening brace of a %s must be on the line following the %s declaration; found %s line(s)'; |
|
| 80 | - $data = [ |
|
| 81 | - $tokens[$stackPtr]['content'], |
|
| 82 | - $tokens[$stackPtr]['content'], |
|
| 83 | - ($braceLine - $classLine - 1), |
|
| 84 | - ]; |
|
| 85 | - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data); |
|
| 86 | - if ($fix === true) { |
|
| 87 | - $phpcsFile->fixer->beginChangeset(); |
|
| 88 | - for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) { |
|
| 89 | - if ($tokens[$i]['line'] === ($tokens[$curlyBrace]['line'] + 1)) { |
|
| 90 | - break; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $phpcsFile->fixer->endChangeset(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return; |
|
| 100 | - }//end if |
|
| 101 | - }//end if |
|
| 102 | - |
|
| 103 | - if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) { |
|
| 104 | - $error = 'Opening %s brace must be on a line by itself'; |
|
| 105 | - |
|
| 106 | - $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($curlyBrace + 1), null, true); |
|
| 107 | - if ($tokens[$nextNonWhitespace]['code'] === T_PHPCS_IGNORE) { |
|
| 108 | - // Don't auto-fix if the next thing is a PHPCS ignore annotation. |
|
| 109 | - $phpcsFile->addError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData); |
|
| 110 | - } else { |
|
| 111 | - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData); |
|
| 112 | - if ($fix === true) { |
|
| 113 | - $phpcsFile->fixer->addNewline($curlyBrace); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) { |
|
| 119 | - $prevContent = $tokens[($curlyBrace - 1)]['content']; |
|
| 120 | - if ($prevContent === $phpcsFile->eolChar) { |
|
| 121 | - $spaces = 0; |
|
| 122 | - } else { |
|
| 123 | - $spaces = $tokens[($curlyBrace - 1)]['length']; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); |
|
| 127 | - $expected = ($tokens[$first]['column'] - 1); |
|
| 128 | - if ($spaces !== $expected) { |
|
| 129 | - $error = 'Expected %s spaces before opening brace; %s found'; |
|
| 130 | - $data = [ |
|
| 131 | - $expected, |
|
| 132 | - $spaces, |
|
| 133 | - ]; |
|
| 134 | - |
|
| 135 | - $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'SpaceBeforeBrace', $data); |
|
| 136 | - if ($fix === true) { |
|
| 137 | - $indent = str_repeat(' ', $expected); |
|
| 138 | - if ($spaces === 0) { |
|
| 139 | - $phpcsFile->fixer->addContentBefore($curlyBrace, $indent); |
|
| 140 | - } else { |
|
| 141 | - $phpcsFile->fixer->replaceToken(($curlyBrace - 1), $indent); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - }//end if |
|
| 146 | - |
|
| 147 | - }//end process() |
|
| 19 | + /** |
|
| 20 | + * Returns an array of tokens this test wants to listen for. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function register() |
|
| 25 | + { |
|
| 26 | + return [ |
|
| 27 | + T_CLASS, |
|
| 28 | + T_INTERFACE, |
|
| 29 | + T_TRAIT, |
|
| 30 | + T_ENUM, |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + }//end register() |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Processes this test, when one of its tokens is encountered. |
|
| 38 | + * |
|
| 39 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 40 | + * @param integer $stackPtr The position of the current token in the |
|
| 41 | + * stack passed in $tokens. |
|
| 42 | + * |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function process(File $phpcsFile, $stackPtr) |
|
| 46 | + { |
|
| 47 | + $tokens = $phpcsFile->getTokens(); |
|
| 48 | + $errorData = [strtolower($tokens[$stackPtr]['content'])]; |
|
| 49 | + |
|
| 50 | + if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
| 51 | + $error = 'Possible parse error: %s missing opening or closing brace'; |
|
| 52 | + $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData); |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $curlyBrace = $tokens[$stackPtr]['scope_opener']; |
|
| 57 | + $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true); |
|
| 58 | + $classLine = $tokens[$lastContent]['line']; |
|
| 59 | + $braceLine = $tokens[$curlyBrace]['line']; |
|
| 60 | + if ($braceLine === $classLine) { |
|
| 61 | + $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line'); |
|
| 62 | + $error = 'Opening brace of a %s must be on the line after the definition'; |
|
| 63 | + $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNewLine', $errorData); |
|
| 64 | + if ($fix === true) { |
|
| 65 | + $phpcsFile->fixer->beginChangeset(); |
|
| 66 | + if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) { |
|
| 67 | + $phpcsFile->fixer->replaceToken(($curlyBrace - 1), ''); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $phpcsFile->fixer->addNewlineBefore($curlyBrace); |
|
| 71 | + $phpcsFile->fixer->endChangeset(); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return; |
|
| 75 | + } else { |
|
| 76 | + $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line'); |
|
| 77 | + |
|
| 78 | + if ($braceLine > ($classLine + 1)) { |
|
| 79 | + $error = 'Opening brace of a %s must be on the line following the %s declaration; found %s line(s)'; |
|
| 80 | + $data = [ |
|
| 81 | + $tokens[$stackPtr]['content'], |
|
| 82 | + $tokens[$stackPtr]['content'], |
|
| 83 | + ($braceLine - $classLine - 1), |
|
| 84 | + ]; |
|
| 85 | + $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data); |
|
| 86 | + if ($fix === true) { |
|
| 87 | + $phpcsFile->fixer->beginChangeset(); |
|
| 88 | + for ($i = ($curlyBrace - 1); $i > $lastContent; $i--) { |
|
| 89 | + if ($tokens[$i]['line'] === ($tokens[$curlyBrace]['line'] + 1)) { |
|
| 90 | + break; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $phpcsFile->fixer->endChangeset(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return; |
|
| 100 | + }//end if |
|
| 101 | + }//end if |
|
| 102 | + |
|
| 103 | + if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) { |
|
| 104 | + $error = 'Opening %s brace must be on a line by itself'; |
|
| 105 | + |
|
| 106 | + $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($curlyBrace + 1), null, true); |
|
| 107 | + if ($tokens[$nextNonWhitespace]['code'] === T_PHPCS_IGNORE) { |
|
| 108 | + // Don't auto-fix if the next thing is a PHPCS ignore annotation. |
|
| 109 | + $phpcsFile->addError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData); |
|
| 110 | + } else { |
|
| 111 | + $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData); |
|
| 112 | + if ($fix === true) { |
|
| 113 | + $phpcsFile->fixer->addNewline($curlyBrace); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) { |
|
| 119 | + $prevContent = $tokens[($curlyBrace - 1)]['content']; |
|
| 120 | + if ($prevContent === $phpcsFile->eolChar) { |
|
| 121 | + $spaces = 0; |
|
| 122 | + } else { |
|
| 123 | + $spaces = $tokens[($curlyBrace - 1)]['length']; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); |
|
| 127 | + $expected = ($tokens[$first]['column'] - 1); |
|
| 128 | + if ($spaces !== $expected) { |
|
| 129 | + $error = 'Expected %s spaces before opening brace; %s found'; |
|
| 130 | + $data = [ |
|
| 131 | + $expected, |
|
| 132 | + $spaces, |
|
| 133 | + ]; |
|
| 134 | + |
|
| 135 | + $fix = $phpcsFile->addFixableError($error, $curlyBrace, 'SpaceBeforeBrace', $data); |
|
| 136 | + if ($fix === true) { |
|
| 137 | + $indent = str_repeat(' ', $expected); |
|
| 138 | + if ($spaces === 0) { |
|
| 139 | + $phpcsFile->fixer->addContentBefore($curlyBrace, $indent); |
|
| 140 | + } else { |
|
| 141 | + $phpcsFile->fixer->replaceToken(($curlyBrace - 1), $indent); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + }//end if |
|
| 146 | + |
|
| 147 | + }//end process() |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | }//end class |
@@ -15,42 +15,42 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the lines where errors should occur. |
|
| 20 | - * |
|
| 21 | - * The key of the array should represent the line number and the value |
|
| 22 | - * should represent the number of errors that should occur on that line. |
|
| 23 | - * |
|
| 24 | - * @return array<int, int> |
|
| 25 | - */ |
|
| 26 | - public function getErrorList() |
|
| 27 | - { |
|
| 28 | - return [ |
|
| 29 | - 8 => 1, |
|
| 30 | - 10 => 1, |
|
| 31 | - 12 => 1, |
|
| 32 | - 14 => 1, |
|
| 33 | - 19 => 1, |
|
| 34 | - 28 => 1, |
|
| 35 | - 30 => 1, |
|
| 36 | - ]; |
|
| 37 | - |
|
| 38 | - }//end getErrorList() |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Returns the lines where warnings should occur. |
|
| 43 | - * |
|
| 44 | - * The key of the array should represent the line number and the value |
|
| 45 | - * should represent the number of warnings that should occur on that line. |
|
| 46 | - * |
|
| 47 | - * @return array<int, int> |
|
| 48 | - */ |
|
| 49 | - public function getWarningList() |
|
| 50 | - { |
|
| 51 | - return []; |
|
| 52 | - |
|
| 53 | - }//end getWarningList() |
|
| 18 | + /** |
|
| 19 | + * Returns the lines where errors should occur. |
|
| 20 | + * |
|
| 21 | + * The key of the array should represent the line number and the value |
|
| 22 | + * should represent the number of errors that should occur on that line. |
|
| 23 | + * |
|
| 24 | + * @return array<int, int> |
|
| 25 | + */ |
|
| 26 | + public function getErrorList() |
|
| 27 | + { |
|
| 28 | + return [ |
|
| 29 | + 8 => 1, |
|
| 30 | + 10 => 1, |
|
| 31 | + 12 => 1, |
|
| 32 | + 14 => 1, |
|
| 33 | + 19 => 1, |
|
| 34 | + 28 => 1, |
|
| 35 | + 30 => 1, |
|
| 36 | + ]; |
|
| 37 | + |
|
| 38 | + }//end getErrorList() |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Returns the lines where warnings should occur. |
|
| 43 | + * |
|
| 44 | + * The key of the array should represent the line number and the value |
|
| 45 | + * should represent the number of warnings that should occur on that line. |
|
| 46 | + * |
|
| 47 | + * @return array<int, int> |
|
| 48 | + */ |
|
| 49 | + public function getWarningList() |
|
| 50 | + { |
|
| 51 | + return []; |
|
| 52 | + |
|
| 53 | + }//end getWarningList() |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | }//end class |