@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return array<int, int> |
27 | 27 | */ |
28 | - public function getErrorList($testFile='') |
|
28 | + public function getErrorList($testFile = '') |
|
29 | 29 | { |
30 | 30 | switch ($testFile) { |
31 | 31 | case 'EndFileNewlineUnitTest.1.inc': |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return array<int, int> |
59 | 59 | */ |
60 | - public function getWarningList($testFile='') |
|
60 | + public function getWarningList($testFile = '') |
|
61 | 61 | { |
62 | 62 | return []; |
63 | 63 |
@@ -15,52 +15,52 @@ |
||
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='') |
|
29 | - { |
|
30 | - switch ($testFile) { |
|
31 | - case 'EndFileNewlineUnitTest.1.inc': |
|
32 | - case 'EndFileNewlineUnitTest.3.inc': |
|
33 | - case 'EndFileNewlineUnitTest.6.inc': |
|
34 | - case 'EndFileNewlineUnitTest.7.inc': |
|
35 | - case 'EndFileNewlineUnitTest.9.inc': |
|
36 | - case 'EndFileNewlineUnitTest.10.inc': |
|
37 | - return [2 => 1]; |
|
38 | - case 'EndFileNewlineUnitTest.11.inc': |
|
39 | - case 'EndFileNewlineUnitTest.12.inc': |
|
40 | - case 'EndFileNewlineUnitTest.13.inc': |
|
41 | - return [1 => 1]; |
|
42 | - default: |
|
43 | - return []; |
|
44 | - }//end switch |
|
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='') |
|
29 | + { |
|
30 | + switch ($testFile) { |
|
31 | + case 'EndFileNewlineUnitTest.1.inc': |
|
32 | + case 'EndFileNewlineUnitTest.3.inc': |
|
33 | + case 'EndFileNewlineUnitTest.6.inc': |
|
34 | + case 'EndFileNewlineUnitTest.7.inc': |
|
35 | + case 'EndFileNewlineUnitTest.9.inc': |
|
36 | + case 'EndFileNewlineUnitTest.10.inc': |
|
37 | + return [2 => 1]; |
|
38 | + case 'EndFileNewlineUnitTest.11.inc': |
|
39 | + case 'EndFileNewlineUnitTest.12.inc': |
|
40 | + case 'EndFileNewlineUnitTest.13.inc': |
|
41 | + return [1 => 1]; |
|
42 | + default: |
|
43 | + return []; |
|
44 | + }//end switch |
|
45 | 45 | |
46 | - }//end getErrorList() |
|
46 | + }//end getErrorList() |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Returns the lines where warnings should occur. |
|
51 | - * |
|
52 | - * The key of the array should represent the line number and the value |
|
53 | - * should represent the number of warnings that should occur on that line. |
|
54 | - * |
|
55 | - * @param string $testFile The name of the file being tested. |
|
56 | - * |
|
57 | - * @return array<int, int> |
|
58 | - */ |
|
59 | - public function getWarningList($testFile='') |
|
60 | - { |
|
61 | - return []; |
|
49 | + /** |
|
50 | + * Returns the lines where warnings should occur. |
|
51 | + * |
|
52 | + * The key of the array should represent the line number and the value |
|
53 | + * should represent the number of warnings that should occur on that line. |
|
54 | + * |
|
55 | + * @param string $testFile The name of the file being tested. |
|
56 | + * |
|
57 | + * @return array<int, int> |
|
58 | + */ |
|
59 | + public function getWarningList($testFile='') |
|
60 | + { |
|
61 | + return []; |
|
62 | 62 | |
63 | - }//end getWarningList() |
|
63 | + }//end getWarningList() |
|
64 | 64 | |
65 | 65 | |
66 | 66 | }//end class |
@@ -28,19 +28,19 @@ |
||
28 | 28 | public function getErrorList($testFile='') |
29 | 29 | { |
30 | 30 | switch ($testFile) { |
31 | - case 'EndFileNewlineUnitTest.1.inc': |
|
32 | - case 'EndFileNewlineUnitTest.3.inc': |
|
33 | - case 'EndFileNewlineUnitTest.6.inc': |
|
34 | - case 'EndFileNewlineUnitTest.7.inc': |
|
35 | - case 'EndFileNewlineUnitTest.9.inc': |
|
36 | - case 'EndFileNewlineUnitTest.10.inc': |
|
37 | - return [2 => 1]; |
|
38 | - case 'EndFileNewlineUnitTest.11.inc': |
|
39 | - case 'EndFileNewlineUnitTest.12.inc': |
|
40 | - case 'EndFileNewlineUnitTest.13.inc': |
|
41 | - return [1 => 1]; |
|
42 | - default: |
|
43 | - return []; |
|
31 | + case 'EndFileNewlineUnitTest.1.inc': |
|
32 | + case 'EndFileNewlineUnitTest.3.inc': |
|
33 | + case 'EndFileNewlineUnitTest.6.inc': |
|
34 | + case 'EndFileNewlineUnitTest.7.inc': |
|
35 | + case 'EndFileNewlineUnitTest.9.inc': |
|
36 | + case 'EndFileNewlineUnitTest.10.inc': |
|
37 | + return [2 => 1]; |
|
38 | + case 'EndFileNewlineUnitTest.11.inc': |
|
39 | + case 'EndFileNewlineUnitTest.12.inc': |
|
40 | + case 'EndFileNewlineUnitTest.13.inc': |
|
41 | + return [1 => 1]; |
|
42 | + default: |
|
43 | + return []; |
|
44 | 44 | }//end switch |
45 | 45 | |
46 | 46 | }//end getErrorList() |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | switch ($foo) { |
37 | - case'Foo': { |
|
38 | - echo 'foo'; |
|
39 | - break; |
|
40 | - } |
|
37 | + case'Foo': { |
|
38 | + echo 'foo'; |
|
39 | + break; |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | while ($i < 10) { |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | switch (true) { |
55 | - case is_resource($value): |
|
56 | - throw new Exception('foo'); |
|
57 | - case is_object($value): |
|
58 | - return 'object'; |
|
55 | + case is_resource($value): |
|
56 | + throw new Exception('foo'); |
|
57 | + case is_object($value): |
|
58 | + return 'object'; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | switch (0) { |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | switch ($foo) { |
108 | - case 1: $bar = 1; break; |
|
109 | - case 2: |
|
108 | + case 1: $bar = 1; break; |
|
109 | + case 2: |
|
110 | 110 | |
111 | - $bar = 2; break; |
|
112 | - case 21: |
|
113 | - case 3: return 3; |
|
114 | - default: $bar = 0; |
|
111 | + $bar = 2; break; |
|
112 | + case 21: |
|
113 | + case 3: return 3; |
|
114 | + default: $bar = 0; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | switch ($foo) { |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | switch ($foo) { |
149 | - case Foo::INTERFACE: |
|
150 | - return self::INTERFACE; |
|
151 | - case Foo::NAMESPACE: |
|
152 | - return self::MODULE; |
|
153 | - case Foo::TRAIT: |
|
154 | - case Foo::ARRAY: |
|
155 | - return self::VALUE; |
|
149 | + case Foo::INTERFACE: |
|
150 | + return self::INTERFACE; |
|
151 | + case Foo::NAMESPACE: |
|
152 | + return self::MODULE; |
|
153 | + case Foo::TRAIT: |
|
154 | + case Foo::ARRAY: |
|
155 | + return self::VALUE; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // OK: Every clause terminates |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | break; |
136 | 136 | } |
137 | 137 | |
138 | -switch($foo) |
|
138 | +switch ($foo) |
|
139 | 139 | { |
140 | 140 | case ('foo'): |
141 | 141 | default: |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | $foo = $foo ? |
267 | - function () { |
|
267 | + function() { |
|
268 | 268 | switch ($a) { |
269 | 269 | case 'a': |
270 | 270 | break; |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | // Issue 3352. |
345 | -switch ( $test ) { |
|
345 | +switch ($test) { |
|
346 | 346 | case 2: // comment followed by empty line |
347 | 347 | |
348 | 348 | break; |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | |
408 | 408 | // Issue #3297. |
409 | 409 | // Okay - finally will always be executed, so all branches are covered by the `return` in finally. |
410 | -switch ( $a ) { |
|
410 | +switch ($a) { |
|
411 | 411 | case 1: |
412 | 412 | try { |
413 | 413 | doSomething(); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | } |
425 | 425 | |
426 | 426 | // Okay - all - non-finally - branches have a terminating statement. |
427 | -switch ( $a ) { |
|
427 | +switch ($a) { |
|
428 | 428 | case 1: |
429 | 429 | try { |
430 | 430 | return false; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | |
445 | 445 | // Okay - finally will always be executed, so all branches are covered by the `return` in finally. |
446 | 446 | // Non-standard structure order. |
447 | -switch ( $a ) { |
|
447 | +switch ($a) { |
|
448 | 448 | case 1: |
449 | 449 | try { |
450 | 450 | doSomething(); |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | |
463 | 463 | // Okay - all - non-finally - branches have a terminating statement. |
464 | 464 | // Non-standard structure order. |
465 | -switch ( $a ) { |
|
465 | +switch ($a) { |
|
466 | 466 | case 1: |
467 | 467 | try { |
468 | 468 | return false; |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | } |
480 | 480 | |
481 | 481 | // All okay, no finally. Any exception still uncaught will terminate the case anyhow, so we're good. |
482 | -switch ( $a ) { |
|
482 | +switch ($a) { |
|
483 | 483 | case 1: |
484 | 484 | try { |
485 | 485 | return false; |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | } |
495 | 495 | |
496 | 496 | // All okay, no catch |
497 | -switch ( $a ) { |
|
497 | +switch ($a) { |
|
498 | 498 | case 1: |
499 | 499 | try { |
500 | 500 | return true; |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | } |
508 | 508 | |
509 | 509 | // All okay, try-catch nested in if. |
510 | -switch ( $a ) { |
|
510 | +switch ($a) { |
|
511 | 511 | case 1: |
512 | 512 | if ($a) { |
513 | 513 | try { |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | // Missing fall-through comment. |
527 | -switch ( $a ) { |
|
527 | +switch ($a) { |
|
528 | 528 | case 1: |
529 | 529 | try { |
530 | 530 | doSomething(); |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | } |
538 | 538 | |
539 | 539 | // Missing fall-through comment. One of the catches does not have a terminating statement. |
540 | -switch ( $a ) { |
|
540 | +switch ($a) { |
|
541 | 541 | case 1: |
542 | 542 | try { |
543 | 543 | return false; |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | } |
555 | 555 | |
556 | 556 | // Missing fall-through comment. Try does not have a terminating statement. |
557 | -switch ( $a ) { |
|
557 | +switch ($a) { |
|
558 | 558 | case 1: |
559 | 559 | try { |
560 | 560 | doSomething(); |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | } |
572 | 572 | |
573 | 573 | // Missing fall-through comment. One of the catches does not have a terminating statement. |
574 | -switch ( $a ) { |
|
574 | +switch ($a) { |
|
575 | 575 | case 1: |
576 | 576 | try { |
577 | 577 | return false; |
@@ -395,10 +395,11 @@ |
||
395 | 395 | |
396 | 396 | switch ($foo) { |
397 | 397 | case 1: |
398 | - if ($bar > 0) /*comment*/ { |
|
398 | + if ($bar > 0) { |
|
399 | + /*comment*/ { |
|
399 | 400 | return doSomething(); |
400 | 401 | } |
401 | - else { |
|
402 | + } else { |
|
402 | 403 | return 1; |
403 | 404 | } |
404 | 405 | case 2: |
@@ -1,598 +1,598 @@ |
||
1 | 1 | <?php |
2 | 2 | switch ($expr) { |
3 | - case 0: |
|
4 | - echo 'First case, with a break'; |
|
5 | - break; |
|
6 | - case 1: |
|
7 | - echo 'Second case, which falls through'; |
|
8 | - // no break |
|
9 | - case 2: |
|
10 | - case 3: |
|
11 | - Case 4: |
|
12 | - echo 'Third case, return instead of break'; |
|
13 | - return; |
|
14 | - Default: |
|
15 | - echo 'Default case'; |
|
16 | - break; |
|
3 | + case 0: |
|
4 | + echo 'First case, with a break'; |
|
5 | + break; |
|
6 | + case 1: |
|
7 | + echo 'Second case, which falls through'; |
|
8 | + // no break |
|
9 | + case 2: |
|
10 | + case 3: |
|
11 | + Case 4: |
|
12 | + echo 'Third case, return instead of break'; |
|
13 | + return; |
|
14 | + Default: |
|
15 | + echo 'Default case'; |
|
16 | + break; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | switch ($expr) { |
20 | - case 0: |
|
21 | - echo 'First case,'; |
|
20 | + case 0: |
|
21 | + echo 'First case,'; |
|
22 | 22 | |
23 | - case 1 : |
|
24 | - echo 'Second case'; |
|
25 | - // no break |
|
26 | - case 2: |
|
27 | - case 3: |
|
28 | - echo 'Third case'; |
|
29 | - return; |
|
23 | + case 1 : |
|
24 | + echo 'Second case'; |
|
25 | + // no break |
|
26 | + case 2: |
|
27 | + case 3: |
|
28 | + echo 'Third case'; |
|
29 | + return; |
|
30 | 30 | |
31 | - default: |
|
32 | - echo 'Default case'; |
|
33 | - break; |
|
31 | + default: |
|
32 | + echo 'Default case'; |
|
33 | + break; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | switch ($foo) { |
37 | - case'Foo': { |
|
38 | - echo 'foo'; |
|
39 | - break; |
|
40 | - } |
|
37 | + case'Foo': { |
|
38 | + echo 'foo'; |
|
39 | + break; |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | while ($i < 10) { |
44 | - switch ($foo) { |
|
45 | - case '1': |
|
46 | - case '2': |
|
47 | - ++$i; |
|
48 | - continue 2; |
|
49 | - case '3': |
|
50 | - return $i; |
|
51 | - } |
|
44 | + switch ($foo) { |
|
45 | + case '1': |
|
46 | + case '2': |
|
47 | + ++$i; |
|
48 | + continue 2; |
|
49 | + case '3': |
|
50 | + return $i; |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | switch (true) { |
55 | - case is_resource($value): |
|
56 | - throw new Exception('foo'); |
|
57 | - case is_object($value): |
|
58 | - return 'object'; |
|
55 | + case is_resource($value): |
|
56 | + throw new Exception('foo'); |
|
57 | + case is_object($value): |
|
58 | + return 'object'; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | switch (0) { |
62 | - case 0: |
|
63 | - switch (1) { |
|
64 | - case 1: |
|
65 | - echo 'a'; |
|
66 | - break; |
|
67 | - } |
|
68 | - break; |
|
62 | + case 0: |
|
63 | + switch (1) { |
|
64 | + case 1: |
|
65 | + echo 'a'; |
|
66 | + break; |
|
67 | + } |
|
68 | + break; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | switch ($foo) { |
72 | - case Foo::ONE: |
|
73 | - case Foo::TWO: |
|
74 | - case Foo::Class: |
|
75 | - break; |
|
72 | + case Foo::ONE: |
|
73 | + case Foo::TWO: |
|
74 | + case Foo::Class: |
|
75 | + break; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | switch (true) { |
79 | - case $value instanceof StdClass: |
|
80 | - return 1; |
|
81 | - case strpos('_', get_class($value)) !== false: |
|
82 | - break; |
|
79 | + case $value instanceof StdClass: |
|
80 | + return 1; |
|
81 | + case strpos('_', get_class($value)) !== false: |
|
82 | + break; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | switch (true) { |
86 | - case $value instanceof StdClass: |
|
87 | - if ($value) { |
|
88 | - return null; |
|
89 | - } |
|
86 | + case $value instanceof StdClass: |
|
87 | + if ($value) { |
|
88 | + return null; |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | use Vendor\Test\FooBar; |
93 | 93 | |
94 | 94 | function test() |
95 | 95 | { |
96 | - switch ($val) { |
|
97 | - case 'foo': |
|
98 | - echo 'foo'; |
|
99 | - break; |
|
100 | - default: |
|
101 | - echo 'foo'; |
|
102 | - } |
|
96 | + switch ($val) { |
|
97 | + case 'foo': |
|
98 | + echo 'foo'; |
|
99 | + break; |
|
100 | + default: |
|
101 | + echo 'foo'; |
|
102 | + } |
|
103 | 103 | |
104 | - exit; |
|
104 | + exit; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | switch ($foo) { |
108 | - case 1: $bar = 1; break; |
|
109 | - case 2: |
|
108 | + case 1: $bar = 1; break; |
|
109 | + case 2: |
|
110 | 110 | |
111 | - $bar = 2; break; |
|
112 | - case 21: |
|
113 | - case 3: return 3; |
|
114 | - default: $bar = 0; |
|
111 | + $bar = 2; break; |
|
112 | + case 21: |
|
113 | + case 3: return 3; |
|
114 | + default: $bar = 0; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | switch ($foo) { |
118 | - case 'foo': // some comment |
|
119 | - echo 'foo'; |
|
120 | - break; |
|
121 | - case 'bar': |
|
122 | - // some comment |
|
123 | - echo 'bar'; |
|
124 | - break; |
|
125 | - case 'baz': // phpcs:ignore Standard.Category.Sniff |
|
126 | - echo 'baz'; |
|
127 | - break; |
|
128 | - case 'boo': |
|
129 | - |
|
130 | - // other comment |
|
131 | - echo 'boo'; |
|
132 | - break; |
|
133 | - default: // other comment |
|
134 | - echo 'default'; |
|
135 | - break; |
|
118 | + case 'foo': // some comment |
|
119 | + echo 'foo'; |
|
120 | + break; |
|
121 | + case 'bar': |
|
122 | + // some comment |
|
123 | + echo 'bar'; |
|
124 | + break; |
|
125 | + case 'baz': // phpcs:ignore Standard.Category.Sniff |
|
126 | + echo 'baz'; |
|
127 | + break; |
|
128 | + case 'boo': |
|
129 | + |
|
130 | + // other comment |
|
131 | + echo 'boo'; |
|
132 | + break; |
|
133 | + default: // other comment |
|
134 | + echo 'default'; |
|
135 | + break; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | switch($foo) |
139 | 139 | { |
140 | - case ('foo'): |
|
141 | - default: |
|
142 | - { |
|
143 | - $foo = 'foo'; |
|
144 | - break; |
|
145 | - } |
|
140 | + case ('foo'): |
|
141 | + default: |
|
142 | + { |
|
143 | + $foo = 'foo'; |
|
144 | + break; |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | switch ($foo) { |
149 | - case Foo::INTERFACE: |
|
150 | - return self::INTERFACE; |
|
151 | - case Foo::NAMESPACE: |
|
152 | - return self::MODULE; |
|
153 | - case Foo::TRAIT: |
|
154 | - case Foo::ARRAY: |
|
155 | - return self::VALUE; |
|
149 | + case Foo::INTERFACE: |
|
150 | + return self::INTERFACE; |
|
151 | + case Foo::NAMESPACE: |
|
152 | + return self::MODULE; |
|
153 | + case Foo::TRAIT: |
|
154 | + case Foo::ARRAY: |
|
155 | + return self::VALUE; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // OK: Every clause terminates |
159 | 159 | switch ($foo) { |
160 | - case 1: |
|
161 | - if ($bar > 0) { |
|
162 | - return 0; |
|
163 | - } else { |
|
164 | - return 1; |
|
165 | - } |
|
166 | - case 2: |
|
167 | - return 2; |
|
160 | + case 1: |
|
161 | + if ($bar > 0) { |
|
162 | + return 0; |
|
163 | + } else { |
|
164 | + return 1; |
|
165 | + } |
|
166 | + case 2: |
|
167 | + return 2; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // ERROR: No else clause |
171 | 171 | switch ($foo) { |
172 | - case 1: |
|
173 | - if ($bar > 0) { |
|
174 | - return 0; |
|
175 | - } elseif ($bar < 0) { |
|
176 | - return 1; |
|
177 | - } |
|
178 | - case 2: |
|
179 | - return 2; |
|
172 | + case 1: |
|
173 | + if ($bar > 0) { |
|
174 | + return 0; |
|
175 | + } elseif ($bar < 0) { |
|
176 | + return 1; |
|
177 | + } |
|
178 | + case 2: |
|
179 | + return 2; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // OK: No fall-through present |
183 | 183 | switch ($foo) { |
184 | - case 1: |
|
185 | - if ($bar > 0) { |
|
186 | - return 0; |
|
187 | - } elseif ($bar < 0) { |
|
188 | - return 1; |
|
189 | - } |
|
184 | + case 1: |
|
185 | + if ($bar > 0) { |
|
186 | + return 0; |
|
187 | + } elseif ($bar < 0) { |
|
188 | + return 1; |
|
189 | + } |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | // ERROR: No else clause (nested) |
193 | 193 | switch ($foo) { |
194 | - case 1: |
|
195 | - if ($bar > 0) { |
|
196 | - return 0; |
|
197 | - } else { |
|
198 | - if ($foo > $bar) { |
|
199 | - continue; |
|
200 | - } |
|
201 | - } |
|
202 | - case 2: |
|
203 | - return 2; |
|
194 | + case 1: |
|
195 | + if ($bar > 0) { |
|
196 | + return 0; |
|
197 | + } else { |
|
198 | + if ($foo > $bar) { |
|
199 | + continue; |
|
200 | + } |
|
201 | + } |
|
202 | + case 2: |
|
203 | + return 2; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // OK: Every clause terminates |
207 | 207 | switch ($foo) { |
208 | - case 1: |
|
209 | - if ($bar > 0) { |
|
210 | - return 0; |
|
211 | - } else { |
|
212 | - if ($foo > $bar) { |
|
213 | - continue; |
|
214 | - } else { |
|
215 | - break; |
|
216 | - } |
|
217 | - } |
|
218 | - case 2: |
|
219 | - return 2; |
|
208 | + case 1: |
|
209 | + if ($bar > 0) { |
|
210 | + return 0; |
|
211 | + } else { |
|
212 | + if ($foo > $bar) { |
|
213 | + continue; |
|
214 | + } else { |
|
215 | + break; |
|
216 | + } |
|
217 | + } |
|
218 | + case 2: |
|
219 | + return 2; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // ERROR: Non-termination IF clause |
223 | 223 | switch ($foo) { |
224 | - case 1: |
|
225 | - if ($bar > 0) { |
|
226 | - $offset = 0; |
|
227 | - } else { |
|
228 | - break; |
|
229 | - } |
|
230 | - case 2: |
|
231 | - return 2; |
|
224 | + case 1: |
|
225 | + if ($bar > 0) { |
|
226 | + $offset = 0; |
|
227 | + } else { |
|
228 | + break; |
|
229 | + } |
|
230 | + case 2: |
|
231 | + return 2; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | // ERROR: Non-termination IF clause (nested) |
235 | 235 | switch ($foo) { |
236 | - case 1: |
|
237 | - if ($bar > 0) { |
|
238 | - continue; |
|
239 | - } else { |
|
240 | - if ($foo > $bar) { |
|
241 | - $offset = 0; |
|
242 | - } else { |
|
243 | - break; |
|
244 | - } |
|
245 | - } |
|
246 | - case 2: |
|
247 | - return 2; |
|
236 | + case 1: |
|
237 | + if ($bar > 0) { |
|
238 | + continue; |
|
239 | + } else { |
|
240 | + if ($foo > $bar) { |
|
241 | + $offset = 0; |
|
242 | + } else { |
|
243 | + break; |
|
244 | + } |
|
245 | + } |
|
246 | + case 2: |
|
247 | + return 2; |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | switch ($sContext) |
251 | 251 | { |
252 | - case 'SOMETHING': |
|
253 | - case 'CONSTANT': |
|
254 | - do_something(); |
|
255 | - break; |
|
256 | - case 'GLOBAL': |
|
257 | - case 'GLOBAL1': |
|
258 | - do_something(); |
|
259 | - // Fall through |
|
260 | - default: |
|
261 | - { |
|
262 | - do_something(); |
|
263 | - } |
|
252 | + case 'SOMETHING': |
|
253 | + case 'CONSTANT': |
|
254 | + do_something(); |
|
255 | + break; |
|
256 | + case 'GLOBAL': |
|
257 | + case 'GLOBAL1': |
|
258 | + do_something(); |
|
259 | + // Fall through |
|
260 | + default: |
|
261 | + { |
|
262 | + do_something(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | $foo = $foo ? |
267 | - function () { |
|
268 | - switch ($a) { |
|
269 | - case 'a': |
|
270 | - break; |
|
271 | - } |
|
272 | - } : |
|
273 | - null; |
|
267 | + function () { |
|
268 | + switch ($a) { |
|
269 | + case 'a': |
|
270 | + break; |
|
271 | + } |
|
272 | + } : |
|
273 | + null; |
|
274 | 274 | |
275 | 275 | switch ($foo) { |
276 | 276 | case Foo::INTERFACE: |
277 | - echo '1'; |
|
278 | - return self::INTERFACE; |
|
277 | + echo '1'; |
|
278 | + return self::INTERFACE; |
|
279 | 279 | case Foo::TRAIT: |
280 | 280 | case Foo::ARRAY: |
281 | - echo '1'; |
|
282 | - return self::VALUE; |
|
281 | + echo '1'; |
|
282 | + return self::VALUE; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | // OK: Every clause terminates |
286 | 286 | switch ($foo) { |
287 | - case 1: |
|
288 | - switch ($bar) { |
|
289 | - case 1: |
|
290 | - return 1; |
|
291 | - default: |
|
292 | - return 3; |
|
293 | - } |
|
294 | - case 2: |
|
295 | - return 2; |
|
287 | + case 1: |
|
288 | + switch ($bar) { |
|
289 | + case 1: |
|
290 | + return 1; |
|
291 | + default: |
|
292 | + return 3; |
|
293 | + } |
|
294 | + case 2: |
|
295 | + return 2; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | // KO: Not every clause terminates |
299 | 299 | switch ($foo) { |
300 | - case 1: |
|
301 | - switch ($bar) { |
|
302 | - case 1: |
|
303 | - return; |
|
304 | - } |
|
305 | - case 2: |
|
306 | - return 2; |
|
300 | + case 1: |
|
301 | + switch ($bar) { |
|
302 | + case 1: |
|
303 | + return; |
|
304 | + } |
|
305 | + case 2: |
|
306 | + return 2; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | // KO: Not every clause terminates |
310 | 310 | switch ($foo) { |
311 | - case 1: |
|
312 | - switch ($bar) { |
|
313 | - case 1: |
|
314 | - return; |
|
315 | - default: |
|
316 | - $a = 1; |
|
317 | - } |
|
318 | - case 2: |
|
319 | - return 2; |
|
311 | + case 1: |
|
312 | + switch ($bar) { |
|
313 | + case 1: |
|
314 | + return; |
|
315 | + default: |
|
316 | + $a = 1; |
|
317 | + } |
|
318 | + case 2: |
|
319 | + return 2; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // OK: Every clause terminates |
323 | 323 | switch ($foo) { |
324 | - case 1: |
|
325 | - switch ($bar) { |
|
326 | - case 1: |
|
327 | - return 1; |
|
328 | - default: |
|
329 | - throw new \Exception(); |
|
330 | - } |
|
331 | - case 2: |
|
332 | - return 2; |
|
324 | + case 1: |
|
325 | + switch ($bar) { |
|
326 | + case 1: |
|
327 | + return 1; |
|
328 | + default: |
|
329 | + throw new \Exception(); |
|
330 | + } |
|
331 | + case 2: |
|
332 | + return 2; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | switch ($foo) { |
336 | - case 1: |
|
337 | - // phpcs:ignore |
|
338 | - case 2: |
|
339 | - return 1; |
|
340 | - case 3: |
|
341 | - return 2; |
|
336 | + case 1: |
|
337 | + // phpcs:ignore |
|
338 | + case 2: |
|
339 | + return 1; |
|
340 | + case 3: |
|
341 | + return 2; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | // Issue 3352. |
345 | 345 | switch ( $test ) { |
346 | - case 2: // comment followed by empty line |
|
346 | + case 2: // comment followed by empty line |
|
347 | 347 | |
348 | - break; |
|
348 | + break; |
|
349 | 349 | |
350 | - case 3: /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments. */ |
|
350 | + case 3: /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments. */ |
|
351 | 351 | |
352 | 352 | |
353 | 353 | |
354 | - break; |
|
354 | + break; |
|
355 | 355 | |
356 | - case 4: /** inline docblock */ |
|
356 | + case 4: /** inline docblock */ |
|
357 | 357 | |
358 | 358 | |
359 | 359 | |
360 | - break; |
|
360 | + break; |
|
361 | 361 | |
362 | - case 5: /* checking how it handles */ /* two trailing comments */ |
|
362 | + case 5: /* checking how it handles */ /* two trailing comments */ |
|
363 | 363 | |
364 | - break; |
|
364 | + break; |
|
365 | 365 | |
366 | - case 6: |
|
367 | - // Comment as first content of the body. |
|
366 | + case 6: |
|
367 | + // Comment as first content of the body. |
|
368 | 368 | |
369 | - break; |
|
369 | + break; |
|
370 | 370 | |
371 | - case 7: |
|
372 | - /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments at start of body. */ |
|
371 | + case 7: |
|
372 | + /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments at start of body. */ |
|
373 | 373 | |
374 | - break; |
|
374 | + break; |
|
375 | 375 | |
376 | - case 8: |
|
377 | - /** inline docblock */ |
|
376 | + case 8: |
|
377 | + /** inline docblock */ |
|
378 | 378 | |
379 | - break; |
|
379 | + break; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | // Handle comments correctly. |
383 | 383 | switch ($foo) { |
384 | - case 1: |
|
385 | - if ($bar > 0) { |
|
386 | - doSomething(); |
|
387 | - } |
|
388 | - // Comment |
|
389 | - else { |
|
390 | - return 1; |
|
391 | - } |
|
392 | - case 2: |
|
393 | - return 2; |
|
384 | + case 1: |
|
385 | + if ($bar > 0) { |
|
386 | + doSomething(); |
|
387 | + } |
|
388 | + // Comment |
|
389 | + else { |
|
390 | + return 1; |
|
391 | + } |
|
392 | + case 2: |
|
393 | + return 2; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | switch ($foo) { |
397 | - case 1: |
|
398 | - if ($bar > 0) /*comment*/ { |
|
399 | - return doSomething(); |
|
400 | - } |
|
401 | - else { |
|
402 | - return 1; |
|
403 | - } |
|
404 | - case 2: |
|
405 | - return 2; |
|
397 | + case 1: |
|
398 | + if ($bar > 0) /*comment*/ { |
|
399 | + return doSomething(); |
|
400 | + } |
|
401 | + else { |
|
402 | + return 1; |
|
403 | + } |
|
404 | + case 2: |
|
405 | + return 2; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | // Issue #3297. |
409 | 409 | // Okay - finally will always be executed, so all branches are covered by the `return` in finally. |
410 | 410 | switch ( $a ) { |
411 | - case 1: |
|
412 | - try { |
|
413 | - doSomething(); |
|
414 | - } catch (Exception $e) { |
|
415 | - doSomething(); |
|
416 | - } catch (AnotherException $e) { |
|
417 | - doSomething(); |
|
418 | - } finally { |
|
419 | - return true; |
|
420 | - } |
|
421 | - default: |
|
422 | - $other = $code; |
|
423 | - break; |
|
411 | + case 1: |
|
412 | + try { |
|
413 | + doSomething(); |
|
414 | + } catch (Exception $e) { |
|
415 | + doSomething(); |
|
416 | + } catch (AnotherException $e) { |
|
417 | + doSomething(); |
|
418 | + } finally { |
|
419 | + return true; |
|
420 | + } |
|
421 | + default: |
|
422 | + $other = $code; |
|
423 | + break; |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | // Okay - all - non-finally - branches have a terminating statement. |
427 | 427 | switch ( $a ) { |
428 | - case 1: |
|
429 | - try { |
|
430 | - return false; |
|
431 | - } catch (Exception $e) /*comment*/ { |
|
432 | - return true; |
|
433 | - } |
|
434 | - // Comment |
|
435 | - catch (AnotherException $e) { |
|
436 | - return true; |
|
437 | - } finally { |
|
438 | - doSomething(); |
|
439 | - } |
|
440 | - default: |
|
441 | - $other = $code; |
|
442 | - break; |
|
428 | + case 1: |
|
429 | + try { |
|
430 | + return false; |
|
431 | + } catch (Exception $e) /*comment*/ { |
|
432 | + return true; |
|
433 | + } |
|
434 | + // Comment |
|
435 | + catch (AnotherException $e) { |
|
436 | + return true; |
|
437 | + } finally { |
|
438 | + doSomething(); |
|
439 | + } |
|
440 | + default: |
|
441 | + $other = $code; |
|
442 | + break; |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | // Okay - finally will always be executed, so all branches are covered by the `return` in finally. |
446 | 446 | // Non-standard structure order. |
447 | 447 | switch ( $a ) { |
448 | - case 1: |
|
449 | - try { |
|
450 | - doSomething(); |
|
451 | - } catch (Exception $e) { |
|
452 | - doSomething(); |
|
453 | - } finally { |
|
454 | - return true; |
|
455 | - } catch (AnotherException $e) { |
|
456 | - doSomething(); |
|
457 | - } |
|
458 | - default: |
|
459 | - $other = $code; |
|
460 | - break; |
|
448 | + case 1: |
|
449 | + try { |
|
450 | + doSomething(); |
|
451 | + } catch (Exception $e) { |
|
452 | + doSomething(); |
|
453 | + } finally { |
|
454 | + return true; |
|
455 | + } catch (AnotherException $e) { |
|
456 | + doSomething(); |
|
457 | + } |
|
458 | + default: |
|
459 | + $other = $code; |
|
460 | + break; |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | // Okay - all - non-finally - branches have a terminating statement. |
464 | 464 | // Non-standard structure order. |
465 | 465 | switch ( $a ) { |
466 | - case 1: |
|
467 | - try { |
|
468 | - return false; |
|
469 | - } finally { |
|
470 | - doSomething(); |
|
471 | - } catch (MyException $e) { |
|
472 | - return true; |
|
473 | - } catch (AnotherException $e) { |
|
474 | - return true; |
|
475 | - } |
|
476 | - default: |
|
477 | - $other = $code; |
|
478 | - break; |
|
466 | + case 1: |
|
467 | + try { |
|
468 | + return false; |
|
469 | + } finally { |
|
470 | + doSomething(); |
|
471 | + } catch (MyException $e) { |
|
472 | + return true; |
|
473 | + } catch (AnotherException $e) { |
|
474 | + return true; |
|
475 | + } |
|
476 | + default: |
|
477 | + $other = $code; |
|
478 | + break; |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | // All okay, no finally. Any exception still uncaught will terminate the case anyhow, so we're good. |
482 | 482 | switch ( $a ) { |
483 | - case 1: |
|
484 | - try { |
|
485 | - return false; |
|
486 | - } catch (MyException $e) { |
|
487 | - return true; |
|
488 | - } catch (AnotherException $e) { |
|
489 | - return true; |
|
490 | - } |
|
491 | - default: |
|
492 | - $other = $code; |
|
493 | - break; |
|
483 | + case 1: |
|
484 | + try { |
|
485 | + return false; |
|
486 | + } catch (MyException $e) { |
|
487 | + return true; |
|
488 | + } catch (AnotherException $e) { |
|
489 | + return true; |
|
490 | + } |
|
491 | + default: |
|
492 | + $other = $code; |
|
493 | + break; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | // All okay, no catch |
497 | 497 | switch ( $a ) { |
498 | - case 1: |
|
499 | - try { |
|
500 | - return true; |
|
501 | - } finally { |
|
502 | - doSomething(); |
|
503 | - } |
|
504 | - case 2: |
|
505 | - $other = $code; |
|
506 | - break; |
|
498 | + case 1: |
|
499 | + try { |
|
500 | + return true; |
|
501 | + } finally { |
|
502 | + doSomething(); |
|
503 | + } |
|
504 | + case 2: |
|
505 | + $other = $code; |
|
506 | + break; |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | // All okay, try-catch nested in if. |
510 | 510 | switch ( $a ) { |
511 | - case 1: |
|
512 | - if ($a) { |
|
513 | - try { |
|
514 | - return true; // Comment. |
|
515 | - } catch (MyException $e) { |
|
516 | - throw new Exception($e->getMessage()); |
|
517 | - } |
|
518 | - } else { |
|
519 | - return true; |
|
520 | - } |
|
521 | - case 2: |
|
522 | - $other = $code; |
|
523 | - break; |
|
511 | + case 1: |
|
512 | + if ($a) { |
|
513 | + try { |
|
514 | + return true; // Comment. |
|
515 | + } catch (MyException $e) { |
|
516 | + throw new Exception($e->getMessage()); |
|
517 | + } |
|
518 | + } else { |
|
519 | + return true; |
|
520 | + } |
|
521 | + case 2: |
|
522 | + $other = $code; |
|
523 | + break; |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | // Missing fall-through comment. |
527 | 527 | switch ( $a ) { |
528 | - case 1: |
|
529 | - try { |
|
530 | - doSomething(); |
|
531 | - } finally { |
|
532 | - doSomething(); |
|
533 | - } |
|
534 | - case 2: |
|
535 | - $other = $code; |
|
536 | - break; |
|
528 | + case 1: |
|
529 | + try { |
|
530 | + doSomething(); |
|
531 | + } finally { |
|
532 | + doSomething(); |
|
533 | + } |
|
534 | + case 2: |
|
535 | + $other = $code; |
|
536 | + break; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | // Missing fall-through comment. One of the catches does not have a terminating statement. |
540 | 540 | switch ( $a ) { |
541 | - case 1: |
|
542 | - try { |
|
543 | - return false; |
|
544 | - } catch (Exception $e) { |
|
545 | - doSomething(); |
|
546 | - } catch (AnotherException $e) { |
|
547 | - return true; |
|
548 | - } finally { |
|
549 | - doSomething(); |
|
550 | - } |
|
551 | - default: |
|
552 | - $other = $code; |
|
553 | - break; |
|
541 | + case 1: |
|
542 | + try { |
|
543 | + return false; |
|
544 | + } catch (Exception $e) { |
|
545 | + doSomething(); |
|
546 | + } catch (AnotherException $e) { |
|
547 | + return true; |
|
548 | + } finally { |
|
549 | + doSomething(); |
|
550 | + } |
|
551 | + default: |
|
552 | + $other = $code; |
|
553 | + break; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | // Missing fall-through comment. Try does not have a terminating statement. |
557 | 557 | switch ( $a ) { |
558 | - case 1: |
|
559 | - try { |
|
560 | - doSomething(); |
|
561 | - } finally { |
|
562 | - doSomething(); |
|
563 | - } catch (Exception $e) { |
|
564 | - return true; |
|
565 | - } catch (AnotherException $e) { |
|
566 | - return true; |
|
567 | - } |
|
568 | - default: |
|
569 | - $other = $code; |
|
570 | - break; |
|
558 | + case 1: |
|
559 | + try { |
|
560 | + doSomething(); |
|
561 | + } finally { |
|
562 | + doSomething(); |
|
563 | + } catch (Exception $e) { |
|
564 | + return true; |
|
565 | + } catch (AnotherException $e) { |
|
566 | + return true; |
|
567 | + } |
|
568 | + default: |
|
569 | + $other = $code; |
|
570 | + break; |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | // Missing fall-through comment. One of the catches does not have a terminating statement. |
574 | 574 | switch ( $a ) { |
575 | - case 1: |
|
576 | - try { |
|
577 | - return false; |
|
578 | - } catch (Exception $e) { |
|
579 | - doSomething(); |
|
580 | - } catch (AnotherException $e) { |
|
581 | - return true; |
|
582 | - } |
|
583 | - default: |
|
584 | - $other = $code; |
|
585 | - break; |
|
575 | + case 1: |
|
576 | + try { |
|
577 | + return false; |
|
578 | + } catch (Exception $e) { |
|
579 | + doSomething(); |
|
580 | + } catch (AnotherException $e) { |
|
581 | + return true; |
|
582 | + } |
|
583 | + default: |
|
584 | + $other = $code; |
|
585 | + break; |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | // Issue 3550 - comment after terminating statement. |
589 | 589 | switch (rand()) { |
590 | - case 1: |
|
591 | - if (rand() === 1) { |
|
592 | - break; |
|
593 | - } else { |
|
594 | - break; // comment |
|
595 | - } |
|
596 | - default: |
|
597 | - break; |
|
590 | + case 1: |
|
591 | + if (rand() === 1) { |
|
592 | + break; |
|
593 | + } else { |
|
594 | + break; // comment |
|
595 | + } |
|
596 | + default: |
|
597 | + break; |
|
598 | 598 | } |
@@ -15,37 +15,37 @@ |
||
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 | - |
|
30 | - }//end getErrorList() |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Returns the lines where warnings should occur. |
|
35 | - * |
|
36 | - * The key of the array should represent the line number and the value |
|
37 | - * should represent the number of warnings that should occur on that line. |
|
38 | - * |
|
39 | - * @return array<int, int> |
|
40 | - */ |
|
41 | - public function getWarningList() |
|
42 | - { |
|
43 | - return [ |
|
44 | - 4 => 1, |
|
45 | - 12 => 1, |
|
46 | - ]; |
|
47 | - |
|
48 | - }//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 | + |
|
30 | + }//end getErrorList() |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Returns the lines where warnings should occur. |
|
35 | + * |
|
36 | + * The key of the array should represent the line number and the value |
|
37 | + * should represent the number of warnings that should occur on that line. |
|
38 | + * |
|
39 | + * @return array<int, int> |
|
40 | + */ |
|
41 | + public function getWarningList() |
|
42 | + { |
|
43 | + return [ |
|
44 | + 4 => 1, |
|
45 | + 12 => 1, |
|
46 | + ]; |
|
47 | + |
|
48 | + }//end getWarningList() |
|
49 | 49 | |
50 | 50 | |
51 | 51 | }//end class |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | -class ClassName extends ParentClass implements \ArrayAccess, \Countable |
|
2 | +class ClassName extends ParentClass implements \ArrayAccess, \Countable |
|
3 | 3 | { |
4 | 4 | // constants, properties, methods |
5 | 5 | } |
6 | 6 | |
7 | -class ClassName extends ParentClass,AnotherParentClass implements \ArrayAccess,\Countable { |
|
7 | +class ClassName extends ParentClass, AnotherParentClass implements \ArrayAccess, \Countable { |
|
8 | 8 | // constants, properties, methods |
9 | 9 | } |
10 | 10 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | class ClassName extends ParentClass implements |
63 | - \Foo\Bar\Countable , |
|
63 | + \Foo\Bar\Countable, |
|
64 | 64 | \Serializable |
65 | 65 | { |
66 | 66 | // constants, properties, methods |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | |
128 | 128 | class ClassName implements |
129 | 129 | |
130 | - \ArrayAccess,\Countable, |
|
130 | + \ArrayAccess, \Countable, |
|
131 | 131 | \Serializable |
132 | 132 | { |
133 | 133 | // constants, properties, methods |
@@ -69,7 +69,9 @@ |
||
69 | 69 | class Test |
70 | 70 | { |
71 | 71 | public function test() { |
72 | - if (1) 1; |
|
72 | + if (1) { |
|
73 | + 1; |
|
74 | + } |
|
73 | 75 | 1 ? (1 ? 1 : 1) : 1; |
74 | 76 | } |
75 | 77 | } |
@@ -1,51 +1,51 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class ClassName extends ParentClass implements \ArrayAccess, \Countable |
3 | 3 | { |
4 | - // constants, properties, methods |
|
4 | + // constants, properties, methods |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class ClassName extends ParentClass,AnotherParentClass implements \ArrayAccess,\Countable { |
8 | - // constants, properties, methods |
|
8 | + // constants, properties, methods |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | class ClassName |
12 | 12 | extends ParentClass |
13 | 13 | implements \ArrayAccess, \Countable |
14 | 14 | { |
15 | - // constants, properties, methods |
|
15 | + // constants, properties, methods |
|
16 | 16 | |
17 | 17 | } |
18 | 18 | |
19 | 19 | class ClassName extends ParentClass implements |
20 | 20 | \ArrayAccess, |
21 | - \Foo\Bar\Countable, |
|
22 | - \Serializable { |
|
23 | - // constants, properties, methods |
|
21 | + \Foo\Bar\Countable, |
|
22 | + \Serializable { |
|
23 | + // constants, properties, methods |
|
24 | 24 | |
25 | 25 | } |
26 | 26 | |
27 | 27 | class ClassName extends ParentClass implements \ArrayAccess, |
28 | - \Countable, |
|
29 | - \Serializable |
|
28 | + \Countable, |
|
29 | + \Serializable |
|
30 | 30 | { |
31 | - // constants, properties, methods |
|
31 | + // constants, properties, methods |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | class ClassName extends ParentClass implements |
35 | - \ArrayAccess, \Countable, \Foo\Serializable |
|
35 | + \ArrayAccess, \Countable, \Foo\Serializable |
|
36 | 36 | { |
37 | - // constants, properties, methods |
|
37 | + // constants, properties, methods |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | // Different indent |
41 | 41 | if ($foo) { |
42 | - class ClassName extends ParentClass implements |
|
43 | - \ArrayAccess, |
|
44 | - \Countable, |
|
45 | - \Serializable |
|
46 | - { |
|
47 | - // constants, properties, methods |
|
48 | - } |
|
42 | + class ClassName extends ParentClass implements |
|
43 | + \ArrayAccess, |
|
44 | + \Countable, |
|
45 | + \Serializable |
|
46 | + { |
|
47 | + // constants, properties, methods |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | class Foo extends \Foo\Bar\Object |
@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | class ClassName extends ParentClass implements |
56 | - \Foo\Bar\Countable, |
|
57 | - \Serializable |
|
56 | + \Foo\Bar\Countable, |
|
57 | + \Serializable |
|
58 | 58 | { |
59 | - // constants, properties, methods |
|
59 | + // constants, properties, methods |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | class ClassName extends ParentClass implements |
63 | - \Foo\Bar\Countable , |
|
64 | - \Serializable |
|
63 | + \Foo\Bar\Countable , |
|
64 | + \Serializable |
|
65 | 65 | { |
66 | - // constants, properties, methods |
|
66 | + // constants, properties, methods |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | class Test |
70 | 70 | { |
71 | - public function test() { |
|
72 | - if (1) 1; |
|
73 | - 1 ? (1 ? 1 : 1) : 1; |
|
74 | - } |
|
71 | + public function test() { |
|
72 | + if (1) 1; |
|
73 | + 1 ? (1 ? 1 : 1) : 1; |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | class MyClass |
@@ -85,18 +85,18 @@ discard block |
||
85 | 85 | |
86 | 86 | class MyClass |
87 | 87 | { |
88 | - // Foo. |
|
88 | + // Foo. |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | class MyClass |
92 | 92 | { |
93 | - // Foo. |
|
93 | + // Foo. |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
97 | 97 | abstract class Test implements |
98 | - TestInterface1, |
|
99 | - TestInterface2 |
|
98 | + TestInterface1, |
|
99 | + TestInterface2 |
|
100 | 100 | { |
101 | 101 | } |
102 | 102 | |
@@ -105,17 +105,17 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | interface MyInterface extends |
108 | - LongInterfaceName1, |
|
109 | - LongInterfaceName2, |
|
110 | - LongInterfaceName3, |
|
111 | - LoginInterfaceName4 |
|
108 | + LongInterfaceName1, |
|
109 | + LongInterfaceName2, |
|
110 | + LongInterfaceName3, |
|
111 | + LoginInterfaceName4 |
|
112 | 112 | { |
113 | 113 | } |
114 | 114 | |
115 | 115 | interface MyInterface extends |
116 | 116 | LongInterfaceName1, |
117 | - LongInterfaceName2, |
|
118 | - LongInterfaceName3, |
|
117 | + LongInterfaceName2, |
|
118 | + LongInterfaceName3, |
|
119 | 119 | LongInterfaceName4 |
120 | 120 | { |
121 | 121 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | |
128 | 128 | class ClassName implements |
129 | 129 | |
130 | - \ArrayAccess,\Countable, |
|
130 | + \ArrayAccess,\Countable, |
|
131 | 131 | \Serializable |
132 | 132 | { |
133 | - // constants, properties, methods |
|
133 | + // constants, properties, methods |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | class C1 |
@@ -140,22 +140,22 @@ discard block |
||
140 | 140 | |
141 | 141 | class Base |
142 | 142 | { |
143 | - protected $anonymous; |
|
143 | + protected $anonymous; |
|
144 | 144 | |
145 | - public function __construct() |
|
146 | - { |
|
147 | - $this->anonymous = new class extends ArrayObject |
|
148 | - { |
|
149 | - public function __construct() |
|
150 | - { |
|
151 | - parent::__construct(['a' => 1, 'b' => 2]); |
|
152 | - } |
|
153 | - }; |
|
154 | - } |
|
145 | + public function __construct() |
|
146 | + { |
|
147 | + $this->anonymous = new class extends ArrayObject |
|
148 | + { |
|
149 | + public function __construct() |
|
150 | + { |
|
151 | + parent::__construct(['a' => 1, 'b' => 2]); |
|
152 | + } |
|
153 | + }; |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | class A extends B |
158 | - implements C |
|
158 | + implements C |
|
159 | 159 | { |
160 | 160 | } |
161 | 161 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | interface I2 extends |
173 | - Bar |
|
173 | + Bar |
|
174 | 174 | { |
175 | 175 | } |
176 | 176 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } |
187 | 187 | |
188 | 188 | class C2 extends |
189 | - Bar |
|
189 | + Bar |
|
190 | 190 | { |
191 | 191 | } |
192 | 192 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | } |
197 | 197 | |
198 | 198 | class C4 extends Foo implements |
199 | - Bar |
|
199 | + Bar |
|
200 | 200 | { |
201 | 201 | } |
202 | 202 | |
@@ -218,17 +218,17 @@ discard block |
||
218 | 218 | } |
219 | 219 | |
220 | 220 | interface I5 extends /* comment */ |
221 | - \Foo\Bar |
|
221 | + \Foo\Bar |
|
222 | 222 | { |
223 | 223 | } |
224 | 224 | |
225 | 225 | interface I6 extends // comment |
226 | - \Foo\Bar |
|
226 | + \Foo\Bar |
|
227 | 227 | { |
228 | 228 | } |
229 | 229 | |
230 | 230 | class C7 extends // comment |
231 | - \Foo\Bar implements \Baz\Bar |
|
231 | + \Foo\Bar implements \Baz\Bar |
|
232 | 232 | { |
233 | 233 | } |
234 | 234 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | $var = new MyClass( |
18 | - function () use ($foo, $bar) { |
|
18 | + function() use ($foo, $bar) { |
|
19 | 19 | return true; |
20 | 20 | } |
21 | 21 | ); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | use Hello, World; |
31 | 31 | } |
32 | 32 | |
33 | -$x = $foo ? function ($foo) use /* comment */ ($bar): int { |
|
33 | +$x = $foo ? function($foo) use /* comment */ ($bar) : int { |
|
34 | 34 | return 1; |
35 | 35 | } : $bar; |
36 | 36 |
@@ -15,28 +15,28 @@ |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | $var = new MyClass( |
18 | - function () use ($foo, $bar) { |
|
19 | - return true; |
|
20 | - } |
|
18 | + function () use ($foo, $bar) { |
|
19 | + return true; |
|
20 | + } |
|
21 | 21 | ); |
22 | 22 | |
23 | 23 | class Container extends Component implements IContainer |
24 | 24 | { |
25 | - use TContainer; |
|
25 | + use TContainer; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | trait HelloWorld |
29 | 29 | { |
30 | - use Hello, World; |
|
30 | + use Hello, World; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | enum SomeEnum |
34 | 34 | { |
35 | - use Hello, World; |
|
35 | + use Hello, World; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | $x = $foo ? function ($foo) use /* comment */ ($bar): int { |
39 | - return 1; |
|
39 | + return 1; |
|
40 | 40 | } : $bar; |
41 | 41 | |
42 | 42 | // Testcase must be on last line in the file. |
@@ -2,15 +2,15 @@ |
||
2 | 2 | namespace bug; |
3 | 3 | |
4 | 4 | use |
5 | - someNS\A; |
|
5 | + someNS\A; |
|
6 | 6 | use someNS\B; |
7 | 7 | class Bug |
8 | 8 | { |
9 | - public function __construct() |
|
10 | - { |
|
11 | - $b = 1; |
|
12 | - $a = function () use ($b) { |
|
13 | - echo $b; |
|
14 | - }; |
|
15 | - } |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + $b = 1; |
|
12 | + $a = function () use ($b) { |
|
13 | + echo $b; |
|
14 | + }; |
|
15 | + } |
|
16 | 16 | } |
@@ -9,7 +9,7 @@ |
||
9 | 9 | public function __construct() |
10 | 10 | { |
11 | 11 | $b = 1; |
12 | - $a = function () use ($b) { |
|
12 | + $a = function() use ($b) { |
|
13 | 13 | echo $b; |
14 | 14 | }; |
15 | 15 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | * |
26 | 26 | * @return array<int, int> |
27 | 27 | */ |
28 | - public function getErrorList($testFile='') |
|
28 | + public function getErrorList($testFile = '') |
|
29 | 29 | { |
30 | 30 | switch ($testFile) { |
31 | 31 | case 'UseDeclarationUnitTest.2.inc': |
@@ -15,83 +15,83 @@ |
||
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='') |
|
29 | - { |
|
30 | - switch ($testFile) { |
|
31 | - case 'UseDeclarationUnitTest.2.inc': |
|
32 | - return [ |
|
33 | - 4 => 1, |
|
34 | - 5 => 1, |
|
35 | - 6 => 1, |
|
36 | - 7 => 1, |
|
37 | - 9 => 1, |
|
38 | - 10 => 1, |
|
39 | - 11 => 1, |
|
40 | - 16 => 1, |
|
41 | - ]; |
|
42 | - case 'UseDeclarationUnitTest.3.inc': |
|
43 | - return [ |
|
44 | - 4 => 1, |
|
45 | - 6 => 1, |
|
46 | - ]; |
|
47 | - case 'UseDeclarationUnitTest.5.inc': |
|
48 | - return [ |
|
49 | - 5 => 1, |
|
50 | - 6 => 1, |
|
51 | - 8 => 1, |
|
52 | - 14 => 1, |
|
53 | - 17 => 1, |
|
54 | - 18 => 1, |
|
55 | - 19 => 1, |
|
56 | - 21 => 1, |
|
57 | - 28 => 1, |
|
58 | - 30 => 1, |
|
59 | - 35 => 1, |
|
60 | - ]; |
|
61 | - case 'UseDeclarationUnitTest.10.inc': |
|
62 | - case 'UseDeclarationUnitTest.11.inc': |
|
63 | - case 'UseDeclarationUnitTest.12.inc': |
|
64 | - case 'UseDeclarationUnitTest.13.inc': |
|
65 | - case 'UseDeclarationUnitTest.14.inc': |
|
66 | - case 'UseDeclarationUnitTest.16.inc': |
|
67 | - case 'UseDeclarationUnitTest.17.inc': |
|
68 | - return [2 => 1]; |
|
69 | - case 'UseDeclarationUnitTest.15.inc': |
|
70 | - return [ |
|
71 | - 3 => 1, |
|
72 | - 4 => 1, |
|
73 | - 5 => 1, |
|
74 | - ]; |
|
75 | - default: |
|
76 | - return []; |
|
77 | - }//end switch |
|
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='') |
|
29 | + { |
|
30 | + switch ($testFile) { |
|
31 | + case 'UseDeclarationUnitTest.2.inc': |
|
32 | + return [ |
|
33 | + 4 => 1, |
|
34 | + 5 => 1, |
|
35 | + 6 => 1, |
|
36 | + 7 => 1, |
|
37 | + 9 => 1, |
|
38 | + 10 => 1, |
|
39 | + 11 => 1, |
|
40 | + 16 => 1, |
|
41 | + ]; |
|
42 | + case 'UseDeclarationUnitTest.3.inc': |
|
43 | + return [ |
|
44 | + 4 => 1, |
|
45 | + 6 => 1, |
|
46 | + ]; |
|
47 | + case 'UseDeclarationUnitTest.5.inc': |
|
48 | + return [ |
|
49 | + 5 => 1, |
|
50 | + 6 => 1, |
|
51 | + 8 => 1, |
|
52 | + 14 => 1, |
|
53 | + 17 => 1, |
|
54 | + 18 => 1, |
|
55 | + 19 => 1, |
|
56 | + 21 => 1, |
|
57 | + 28 => 1, |
|
58 | + 30 => 1, |
|
59 | + 35 => 1, |
|
60 | + ]; |
|
61 | + case 'UseDeclarationUnitTest.10.inc': |
|
62 | + case 'UseDeclarationUnitTest.11.inc': |
|
63 | + case 'UseDeclarationUnitTest.12.inc': |
|
64 | + case 'UseDeclarationUnitTest.13.inc': |
|
65 | + case 'UseDeclarationUnitTest.14.inc': |
|
66 | + case 'UseDeclarationUnitTest.16.inc': |
|
67 | + case 'UseDeclarationUnitTest.17.inc': |
|
68 | + return [2 => 1]; |
|
69 | + case 'UseDeclarationUnitTest.15.inc': |
|
70 | + return [ |
|
71 | + 3 => 1, |
|
72 | + 4 => 1, |
|
73 | + 5 => 1, |
|
74 | + ]; |
|
75 | + default: |
|
76 | + return []; |
|
77 | + }//end switch |
|
78 | 78 | |
79 | - }//end getErrorList() |
|
79 | + }//end getErrorList() |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * Returns the lines where warnings should occur. |
|
84 | - * |
|
85 | - * The key of the array should represent the line number and the value |
|
86 | - * should represent the number of warnings that should occur on that line. |
|
87 | - * |
|
88 | - * @return array<int, int> |
|
89 | - */ |
|
90 | - public function getWarningList() |
|
91 | - { |
|
92 | - return []; |
|
82 | + /** |
|
83 | + * Returns the lines where warnings should occur. |
|
84 | + * |
|
85 | + * The key of the array should represent the line number and the value |
|
86 | + * should represent the number of warnings that should occur on that line. |
|
87 | + * |
|
88 | + * @return array<int, int> |
|
89 | + */ |
|
90 | + public function getWarningList() |
|
91 | + { |
|
92 | + return []; |
|
93 | 93 | |
94 | - }//end getWarningList() |
|
94 | + }//end getWarningList() |
|
95 | 95 | |
96 | 96 | |
97 | 97 | }//end class |
@@ -28,52 +28,52 @@ |
||
28 | 28 | public function getErrorList($testFile='') |
29 | 29 | { |
30 | 30 | switch ($testFile) { |
31 | - case 'UseDeclarationUnitTest.2.inc': |
|
32 | - return [ |
|
33 | - 4 => 1, |
|
34 | - 5 => 1, |
|
35 | - 6 => 1, |
|
36 | - 7 => 1, |
|
37 | - 9 => 1, |
|
38 | - 10 => 1, |
|
39 | - 11 => 1, |
|
40 | - 16 => 1, |
|
41 | - ]; |
|
42 | - case 'UseDeclarationUnitTest.3.inc': |
|
43 | - return [ |
|
44 | - 4 => 1, |
|
45 | - 6 => 1, |
|
46 | - ]; |
|
47 | - case 'UseDeclarationUnitTest.5.inc': |
|
48 | - return [ |
|
49 | - 5 => 1, |
|
50 | - 6 => 1, |
|
51 | - 8 => 1, |
|
52 | - 14 => 1, |
|
53 | - 17 => 1, |
|
54 | - 18 => 1, |
|
55 | - 19 => 1, |
|
56 | - 21 => 1, |
|
57 | - 28 => 1, |
|
58 | - 30 => 1, |
|
59 | - 35 => 1, |
|
60 | - ]; |
|
61 | - case 'UseDeclarationUnitTest.10.inc': |
|
62 | - case 'UseDeclarationUnitTest.11.inc': |
|
63 | - case 'UseDeclarationUnitTest.12.inc': |
|
64 | - case 'UseDeclarationUnitTest.13.inc': |
|
65 | - case 'UseDeclarationUnitTest.14.inc': |
|
66 | - case 'UseDeclarationUnitTest.16.inc': |
|
67 | - case 'UseDeclarationUnitTest.17.inc': |
|
68 | - return [2 => 1]; |
|
69 | - case 'UseDeclarationUnitTest.15.inc': |
|
70 | - return [ |
|
71 | - 3 => 1, |
|
72 | - 4 => 1, |
|
73 | - 5 => 1, |
|
74 | - ]; |
|
75 | - default: |
|
76 | - return []; |
|
31 | + case 'UseDeclarationUnitTest.2.inc': |
|
32 | + return [ |
|
33 | + 4 => 1, |
|
34 | + 5 => 1, |
|
35 | + 6 => 1, |
|
36 | + 7 => 1, |
|
37 | + 9 => 1, |
|
38 | + 10 => 1, |
|
39 | + 11 => 1, |
|
40 | + 16 => 1, |
|
41 | + ]; |
|
42 | + case 'UseDeclarationUnitTest.3.inc': |
|
43 | + return [ |
|
44 | + 4 => 1, |
|
45 | + 6 => 1, |
|
46 | + ]; |
|
47 | + case 'UseDeclarationUnitTest.5.inc': |
|
48 | + return [ |
|
49 | + 5 => 1, |
|
50 | + 6 => 1, |
|
51 | + 8 => 1, |
|
52 | + 14 => 1, |
|
53 | + 17 => 1, |
|
54 | + 18 => 1, |
|
55 | + 19 => 1, |
|
56 | + 21 => 1, |
|
57 | + 28 => 1, |
|
58 | + 30 => 1, |
|
59 | + 35 => 1, |
|
60 | + ]; |
|
61 | + case 'UseDeclarationUnitTest.10.inc': |
|
62 | + case 'UseDeclarationUnitTest.11.inc': |
|
63 | + case 'UseDeclarationUnitTest.12.inc': |
|
64 | + case 'UseDeclarationUnitTest.13.inc': |
|
65 | + case 'UseDeclarationUnitTest.14.inc': |
|
66 | + case 'UseDeclarationUnitTest.16.inc': |
|
67 | + case 'UseDeclarationUnitTest.17.inc': |
|
68 | + return [2 => 1]; |
|
69 | + case 'UseDeclarationUnitTest.15.inc': |
|
70 | + return [ |
|
71 | + 3 => 1, |
|
72 | + 4 => 1, |
|
73 | + 5 => 1, |
|
74 | + ]; |
|
75 | + default: |
|
76 | + return []; |
|
77 | 77 | }//end switch |
78 | 78 | |
79 | 79 | }//end getErrorList() |
@@ -64,18 +64,18 @@ |
||
64 | 64 | $prefix = $stackPtr; |
65 | 65 | while (($prefix = $phpcsFile->findPrevious(Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { |
66 | 66 | switch ($tokens[$prefix]['code']) { |
67 | - case T_STATIC: |
|
68 | - $static = $prefix; |
|
69 | - break; |
|
70 | - case T_ABSTRACT: |
|
71 | - $abstract = $prefix; |
|
72 | - break; |
|
73 | - case T_FINAL: |
|
74 | - $final = $prefix; |
|
75 | - break; |
|
76 | - default: |
|
77 | - $visibility = $prefix; |
|
78 | - break; |
|
67 | + case T_STATIC: |
|
68 | + $static = $prefix; |
|
69 | + break; |
|
70 | + case T_ABSTRACT: |
|
71 | + $abstract = $prefix; |
|
72 | + break; |
|
73 | + case T_FINAL: |
|
74 | + $final = $prefix; |
|
75 | + break; |
|
76 | + default: |
|
77 | + $visibility = $prefix; |
|
78 | + break; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 |
@@ -17,146 +17,146 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - parent::__construct(Tokens::$ooScopeTokens, [T_FUNCTION]); |
|
26 | - |
|
27 | - }//end __construct() |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * Processes the function tokens within the class. |
|
32 | - * |
|
33 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
34 | - * @param int $stackPtr The position where the token was found. |
|
35 | - * @param int $currScope The current scope opener token. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
|
40 | - { |
|
41 | - $tokens = $phpcsFile->getTokens(); |
|
42 | - |
|
43 | - // Determine if this is a function which needs to be examined. |
|
44 | - $conditions = $tokens[$stackPtr]['conditions']; |
|
45 | - end($conditions); |
|
46 | - $deepestScope = key($conditions); |
|
47 | - if ($deepestScope !== $currScope) { |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
52 | - if ($methodName === null) { |
|
53 | - // Ignore closures. |
|
54 | - return; |
|
55 | - } |
|
56 | - |
|
57 | - if ($methodName[0] === '_' && isset($methodName[1]) === true && $methodName[1] !== '_') { |
|
58 | - $error = 'Method name "%s" should not be prefixed with an underscore to indicate visibility'; |
|
59 | - $data = [$methodName]; |
|
60 | - $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); |
|
61 | - } |
|
62 | - |
|
63 | - $visibility = 0; |
|
64 | - $static = 0; |
|
65 | - $abstract = 0; |
|
66 | - $final = 0; |
|
67 | - |
|
68 | - $find = (Tokens::$methodPrefixes + Tokens::$emptyTokens); |
|
69 | - $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); |
|
70 | - |
|
71 | - $prefix = $stackPtr; |
|
72 | - while (($prefix = $phpcsFile->findPrevious(Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { |
|
73 | - switch ($tokens[$prefix]['code']) { |
|
74 | - case T_STATIC: |
|
75 | - $static = $prefix; |
|
76 | - break; |
|
77 | - case T_ABSTRACT: |
|
78 | - $abstract = $prefix; |
|
79 | - break; |
|
80 | - case T_FINAL: |
|
81 | - $final = $prefix; |
|
82 | - break; |
|
83 | - default: |
|
84 | - $visibility = $prefix; |
|
85 | - break; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - $fixes = []; |
|
90 | - |
|
91 | - if ($visibility !== 0 && $final > $visibility) { |
|
92 | - $error = 'The final declaration must precede the visibility declaration'; |
|
93 | - $fix = $phpcsFile->addFixableError($error, $final, 'FinalAfterVisibility'); |
|
94 | - if ($fix === true) { |
|
95 | - $fixes[$final] = ''; |
|
96 | - $fixes[($final + 1)] = ''; |
|
97 | - if (isset($fixes[$visibility]) === true) { |
|
98 | - $fixes[$visibility] = 'final '.$fixes[$visibility]; |
|
99 | - } else { |
|
100 | - $fixes[$visibility] = 'final '.$tokens[$visibility]['content']; |
|
101 | - } |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - if ($visibility !== 0 && $abstract > $visibility) { |
|
106 | - $error = 'The abstract declaration must precede the visibility declaration'; |
|
107 | - $fix = $phpcsFile->addFixableError($error, $abstract, 'AbstractAfterVisibility'); |
|
108 | - if ($fix === true) { |
|
109 | - $fixes[$abstract] = ''; |
|
110 | - $fixes[($abstract + 1)] = ''; |
|
111 | - if (isset($fixes[$visibility]) === true) { |
|
112 | - $fixes[$visibility] = 'abstract '.$fixes[$visibility]; |
|
113 | - } else { |
|
114 | - $fixes[$visibility] = 'abstract '.$tokens[$visibility]['content']; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - if ($static !== 0 && $static < $visibility) { |
|
120 | - $error = 'The static declaration must come after the visibility declaration'; |
|
121 | - $fix = $phpcsFile->addFixableError($error, $static, 'StaticBeforeVisibility'); |
|
122 | - if ($fix === true) { |
|
123 | - $fixes[$static] = ''; |
|
124 | - $fixes[($static + 1)] = ''; |
|
125 | - if (isset($fixes[$visibility]) === true) { |
|
126 | - $fixes[$visibility] .= ' static'; |
|
127 | - } else { |
|
128 | - $fixes[$visibility] = $tokens[$visibility]['content'].' static'; |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - // Batch all the fixes together to reduce the possibility of conflicts. |
|
134 | - if (empty($fixes) === false) { |
|
135 | - $phpcsFile->fixer->beginChangeset(); |
|
136 | - foreach ($fixes as $stackPtr => $content) { |
|
137 | - $phpcsFile->fixer->replaceToken($stackPtr, $content); |
|
138 | - } |
|
139 | - |
|
140 | - $phpcsFile->fixer->endChangeset(); |
|
141 | - } |
|
142 | - |
|
143 | - }//end processTokenWithinScope() |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Processes a token that is found within the scope that this test is |
|
148 | - * listening to. |
|
149 | - * |
|
150 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
151 | - * @param int $stackPtr The position in the stack where this |
|
152 | - * token was found. |
|
153 | - * |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
|
157 | - { |
|
158 | - |
|
159 | - }//end processTokenOutsideScope() |
|
20 | + /** |
|
21 | + * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + parent::__construct(Tokens::$ooScopeTokens, [T_FUNCTION]); |
|
26 | + |
|
27 | + }//end __construct() |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * Processes the function tokens within the class. |
|
32 | + * |
|
33 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
34 | + * @param int $stackPtr The position where the token was found. |
|
35 | + * @param int $currScope The current scope opener token. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
|
40 | + { |
|
41 | + $tokens = $phpcsFile->getTokens(); |
|
42 | + |
|
43 | + // Determine if this is a function which needs to be examined. |
|
44 | + $conditions = $tokens[$stackPtr]['conditions']; |
|
45 | + end($conditions); |
|
46 | + $deepestScope = key($conditions); |
|
47 | + if ($deepestScope !== $currScope) { |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
52 | + if ($methodName === null) { |
|
53 | + // Ignore closures. |
|
54 | + return; |
|
55 | + } |
|
56 | + |
|
57 | + if ($methodName[0] === '_' && isset($methodName[1]) === true && $methodName[1] !== '_') { |
|
58 | + $error = 'Method name "%s" should not be prefixed with an underscore to indicate visibility'; |
|
59 | + $data = [$methodName]; |
|
60 | + $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); |
|
61 | + } |
|
62 | + |
|
63 | + $visibility = 0; |
|
64 | + $static = 0; |
|
65 | + $abstract = 0; |
|
66 | + $final = 0; |
|
67 | + |
|
68 | + $find = (Tokens::$methodPrefixes + Tokens::$emptyTokens); |
|
69 | + $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); |
|
70 | + |
|
71 | + $prefix = $stackPtr; |
|
72 | + while (($prefix = $phpcsFile->findPrevious(Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { |
|
73 | + switch ($tokens[$prefix]['code']) { |
|
74 | + case T_STATIC: |
|
75 | + $static = $prefix; |
|
76 | + break; |
|
77 | + case T_ABSTRACT: |
|
78 | + $abstract = $prefix; |
|
79 | + break; |
|
80 | + case T_FINAL: |
|
81 | + $final = $prefix; |
|
82 | + break; |
|
83 | + default: |
|
84 | + $visibility = $prefix; |
|
85 | + break; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + $fixes = []; |
|
90 | + |
|
91 | + if ($visibility !== 0 && $final > $visibility) { |
|
92 | + $error = 'The final declaration must precede the visibility declaration'; |
|
93 | + $fix = $phpcsFile->addFixableError($error, $final, 'FinalAfterVisibility'); |
|
94 | + if ($fix === true) { |
|
95 | + $fixes[$final] = ''; |
|
96 | + $fixes[($final + 1)] = ''; |
|
97 | + if (isset($fixes[$visibility]) === true) { |
|
98 | + $fixes[$visibility] = 'final '.$fixes[$visibility]; |
|
99 | + } else { |
|
100 | + $fixes[$visibility] = 'final '.$tokens[$visibility]['content']; |
|
101 | + } |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + if ($visibility !== 0 && $abstract > $visibility) { |
|
106 | + $error = 'The abstract declaration must precede the visibility declaration'; |
|
107 | + $fix = $phpcsFile->addFixableError($error, $abstract, 'AbstractAfterVisibility'); |
|
108 | + if ($fix === true) { |
|
109 | + $fixes[$abstract] = ''; |
|
110 | + $fixes[($abstract + 1)] = ''; |
|
111 | + if (isset($fixes[$visibility]) === true) { |
|
112 | + $fixes[$visibility] = 'abstract '.$fixes[$visibility]; |
|
113 | + } else { |
|
114 | + $fixes[$visibility] = 'abstract '.$tokens[$visibility]['content']; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + if ($static !== 0 && $static < $visibility) { |
|
120 | + $error = 'The static declaration must come after the visibility declaration'; |
|
121 | + $fix = $phpcsFile->addFixableError($error, $static, 'StaticBeforeVisibility'); |
|
122 | + if ($fix === true) { |
|
123 | + $fixes[$static] = ''; |
|
124 | + $fixes[($static + 1)] = ''; |
|
125 | + if (isset($fixes[$visibility]) === true) { |
|
126 | + $fixes[$visibility] .= ' static'; |
|
127 | + } else { |
|
128 | + $fixes[$visibility] = $tokens[$visibility]['content'].' static'; |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + // Batch all the fixes together to reduce the possibility of conflicts. |
|
134 | + if (empty($fixes) === false) { |
|
135 | + $phpcsFile->fixer->beginChangeset(); |
|
136 | + foreach ($fixes as $stackPtr => $content) { |
|
137 | + $phpcsFile->fixer->replaceToken($stackPtr, $content); |
|
138 | + } |
|
139 | + |
|
140 | + $phpcsFile->fixer->endChangeset(); |
|
141 | + } |
|
142 | + |
|
143 | + }//end processTokenWithinScope() |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Processes a token that is found within the scope that this test is |
|
148 | + * listening to. |
|
149 | + * |
|
150 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
151 | + * @param int $stackPtr The position in the stack where this |
|
152 | + * token was found. |
|
153 | + * |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
|
157 | + { |
|
158 | + |
|
159 | + }//end processTokenOutsideScope() |
|
160 | 160 | |
161 | 161 | |
162 | 162 | }//end class |
@@ -16,57 +16,57 @@ |
||
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_ELSE, |
|
28 | - T_ELSEIF, |
|
29 | - ]; |
|
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_ELSE, |
|
28 | + T_ELSEIF, |
|
29 | + ]; |
|
30 | 30 | |
31 | - }//end register() |
|
31 | + }//end register() |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Processes this test, when one of its tokens is encountered. |
|
36 | - * |
|
37 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
38 | - * @param int $stackPtr The position of the current token in the |
|
39 | - * stack passed in $tokens. |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function process(File $phpcsFile, $stackPtr) |
|
44 | - { |
|
45 | - $tokens = $phpcsFile->getTokens(); |
|
34 | + /** |
|
35 | + * Processes this test, when one of its tokens is encountered. |
|
36 | + * |
|
37 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
38 | + * @param int $stackPtr The position of the current token in the |
|
39 | + * stack passed in $tokens. |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function process(File $phpcsFile, $stackPtr) |
|
44 | + { |
|
45 | + $tokens = $phpcsFile->getTokens(); |
|
46 | 46 | |
47 | - if ($tokens[$stackPtr]['code'] === T_ELSEIF) { |
|
48 | - $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'elseif'); |
|
49 | - return; |
|
50 | - } |
|
47 | + if ($tokens[$stackPtr]['code'] === T_ELSEIF) { |
|
48 | + $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'elseif'); |
|
49 | + return; |
|
50 | + } |
|
51 | 51 | |
52 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
53 | - if ($tokens[$next]['code'] === T_IF) { |
|
54 | - $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'else if'); |
|
55 | - $error = 'Usage of ELSE IF is discouraged; use ELSEIF instead'; |
|
56 | - $fix = $phpcsFile->addFixableWarning($error, $stackPtr, 'NotAllowed'); |
|
52 | + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
53 | + if ($tokens[$next]['code'] === T_IF) { |
|
54 | + $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'else if'); |
|
55 | + $error = 'Usage of ELSE IF is discouraged; use ELSEIF instead'; |
|
56 | + $fix = $phpcsFile->addFixableWarning($error, $stackPtr, 'NotAllowed'); |
|
57 | 57 | |
58 | - if ($fix === true) { |
|
59 | - $phpcsFile->fixer->beginChangeset(); |
|
60 | - $phpcsFile->fixer->replaceToken($stackPtr, 'elseif'); |
|
61 | - for ($i = ($stackPtr + 1); $i <= $next; $i++) { |
|
62 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
63 | - } |
|
58 | + if ($fix === true) { |
|
59 | + $phpcsFile->fixer->beginChangeset(); |
|
60 | + $phpcsFile->fixer->replaceToken($stackPtr, 'elseif'); |
|
61 | + for ($i = ($stackPtr + 1); $i <= $next; $i++) { |
|
62 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
63 | + } |
|
64 | 64 | |
65 | - $phpcsFile->fixer->endChangeset(); |
|
66 | - } |
|
67 | - } |
|
65 | + $phpcsFile->fixer->endChangeset(); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - }//end process() |
|
69 | + }//end process() |
|
70 | 70 | |
71 | 71 | |
72 | 72 | }//end class |