File tree Expand file tree Collapse file tree 5 files changed +110
-2
lines changed Expand file tree Collapse file tree 5 files changed +110
-2
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ exceptions/differences/extensions (:white_check_mark: are the implemented sniffs
33
33
- :white_check_mark : Assignment in condition is not allowed
34
34
- :white_check_mark : Use parentheses when creating new instances that do not require arguments ` $foo = new Foo() `
35
35
- :white_check_mark : Use Null Coalesce Operator ` $foo = $bar ?? $baz `
36
+ - :white_check_mark : Use early return
36
37
37
38
For full reference of enforcements, go through ` lib/Doctrine/ruleset.xml ` where each sniff is briefly described.
38
39
Original file line number Diff line number Diff line change 132
132
<rule ref =" SlevomatCodingStandard.ControlStructures.DisallowYodaComparison" />
133
133
<!-- Forbid weak comparisons -->
134
134
<rule ref =" SlevomatCodingStandard.ControlStructures.DisallowEqualOperators" />
135
+ <!-- Require usage of early exit -->
136
+ <rule ref =" SlevomatCodingStandard.ControlStructures.EarlyExit" />
135
137
<!-- Require language constructs without parentheses -->
136
138
<rule ref =" SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses" />
137
139
<!-- Require new instances with parentheses -->
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ PHP CODE SNIFFER REPORT SUMMARY
4
4
FILE ERRORS WARNINGS
5
5
----------------------------------------------------------------------
6
6
tests/input/concatenation_spacing.php 24 0
7
+ tests/input/EarlyReturn.php 4 0
7
8
tests/input/example-class.php 19 0
8
9
tests/input/forbidden-comments.php 4 0
9
10
tests/input/forbidden-functions.php 3 0
@@ -14,9 +15,9 @@ tests/input/return_type_on_closures.php 21 0
14
15
tests/input/return_type_on_methods.php 17 0
15
16
tests/input/test-case.php 6 0
16
17
----------------------------------------------------------------------
17
- A TOTAL OF 121 ERRORS AND 0 WARNINGS WERE FOUND IN 10 FILES
18
+ A TOTAL OF 125 ERRORS AND 0 WARNINGS WERE FOUND IN 11 FILES
18
19
----------------------------------------------------------------------
19
- PHPCBF CAN FIX 106 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
20
+ PHPCBF CAN FIX 110 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
20
21
----------------------------------------------------------------------
21
22
22
23
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Example ;
6
+
7
+ class EarlyReturn
8
+ {
9
+ public function bar () : bool
10
+ {
11
+ if ($ bar === 'bar ' ) {
12
+ return true ;
13
+ }
14
+
15
+ return false ;
16
+ }
17
+
18
+ public function foo () : ?string
19
+ {
20
+ foreach ($ itens as $ item ) {
21
+ if (! $ item ->isItem ()) {
22
+ return 'There is an item that is not an item ' ;
23
+ }
24
+
25
+ continue ;
26
+ }
27
+
28
+ return null ;
29
+ }
30
+
31
+ public function baz () : string
32
+ {
33
+ if ($ number > 0 ) {
34
+ return 'Number is grater then 0 ' ;
35
+ }
36
+
37
+ exit ;
38
+ }
39
+
40
+ public function quoox () : bool
41
+ {
42
+ if (true !== 'true ' ) {
43
+ return false ;
44
+ }
45
+
46
+ if (false === false ) {
47
+ return true ;
48
+ }
49
+
50
+ return true ;
51
+ }
52
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Example ;
6
+
7
+ class EarlyReturn
8
+ {
9
+ public function bar () : bool
10
+ {
11
+ if ($ bar === 'bar ' ) {
12
+ return true ;
13
+ } else {
14
+ return false ;
15
+ }
16
+ }
17
+
18
+ public function foo () : ?string
19
+ {
20
+ foreach ($ itens as $ item ) {
21
+ if (! $ item ->isItem ()) {
22
+ return 'There is an item that is not an item ' ;
23
+ } else {
24
+ continue ;
25
+ }
26
+ }
27
+
28
+ return null ;
29
+ }
30
+
31
+ public function baz () : string
32
+ {
33
+ if ($ number > 0 ) {
34
+ return 'Number is grater then 0 ' ;
35
+ } else {
36
+ exit ;
37
+ }
38
+ }
39
+
40
+ public function quoox () : bool
41
+ {
42
+ if (true === 'true ' ) {
43
+ if (false === false ) {
44
+ return true ;
45
+ }
46
+ } else {
47
+ return false ;
48
+ }
49
+
50
+ return true ;
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments