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
3333- :white_check_mark : Assignment in condition is not allowed
3434- :white_check_mark : Use parentheses when creating new instances that do not require arguments ` $foo = new Foo() `
3535- :white_check_mark : Use Null Coalesce Operator ` $foo = $bar ?? $baz `
36+ - :white_check_mark : Use early return
3637
3738For full reference of enforcements, go through ` lib/Doctrine/ruleset.xml ` where each sniff is briefly described.
3839
Original file line number Diff line number Diff line change 132132 <rule ref =" SlevomatCodingStandard.ControlStructures.DisallowYodaComparison" />
133133 <!-- Forbid weak comparisons -->
134134 <rule ref =" SlevomatCodingStandard.ControlStructures.DisallowEqualOperators" />
135+ <!-- Require usage of early exit -->
136+ <rule ref =" SlevomatCodingStandard.ControlStructures.EarlyExit" />
135137 <!-- Require language constructs without parentheses -->
136138 <rule ref =" SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses" />
137139 <!-- Require new instances with parentheses -->
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ PHP CODE SNIFFER REPORT SUMMARY
44FILE ERRORS WARNINGS
55----------------------------------------------------------------------
66tests/input/concatenation_spacing.php 24 0
7+ tests/input/EarlyReturn.php 4 0
78tests/input/example-class.php 19 0
89tests/input/forbidden-comments.php 4 0
910tests/input/forbidden-functions.php 3 0
@@ -14,9 +15,9 @@ tests/input/return_type_on_closures.php 21 0
1415tests/input/return_type_on_methods.php 17 0
1516tests/input/test-case.php 6 0
1617----------------------------------------------------------------------
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
1819----------------------------------------------------------------------
19- PHPCBF CAN FIX 106 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
20+ PHPCBF CAN FIX 110 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
2021----------------------------------------------------------------------
2122
2223
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