File tree Expand file tree Collapse file tree 2 files changed +49
-11
lines changed Expand file tree Collapse file tree 2 files changed +49
-11
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public function enterNode(Node $node): void
44
44
if ($ node instanceof Node \Stmt \Function_ ||
45
45
$ node instanceof Node \Stmt \ClassMethod
46
46
) {
47
- $ this ->setLineBranch ($ node ->getStartLine (), $ node ->getEndLine (), ++$ this ->nextBranch );
47
+ $ this ->setLineBranch ($ node ->getStartLine (), $ node ->getEndLine () - 1 , ++$ this ->nextBranch );
48
48
49
49
return ;
50
50
}
@@ -138,8 +138,30 @@ public function enterNode(Node $node): void
138
138
return ;
139
139
}
140
140
141
+ if ($ node instanceof Node \Stmt \Return_) {
142
+ $ returnBranch = $ this ->executableLinesGroupedByBranch [$ node ->getStartLine ()];
143
+ $ returnEndLine = $ node ->getEndLine ();
144
+ $ nextBranch = null ;
145
+
146
+ foreach ($ this ->executableLinesGroupedByBranch as $ line => $ branch ) {
147
+ if ($ line <= $ returnEndLine || $ branch !== $ returnBranch ) {
148
+ continue ;
149
+ }
150
+
151
+ if (null === $ nextBranch ) {
152
+ $ nextBranch = ++$ this ->nextBranch ;
153
+ }
154
+
155
+ $ this ->executableLinesGroupedByBranch [$ line ] = $ nextBranch ;
156
+ }
157
+
158
+ return ;
159
+ }
160
+
141
161
if ($ node instanceof Node \Stmt \Declare_) {
142
162
$ this ->unsets [] = range ($ node ->getStartLine (), $ node ->getEndLine ());
163
+
164
+ return ;
143
165
}
144
166
145
167
if ($ node instanceof Node \Identifier) {
Original file line number Diff line number Diff line change 13
13
function simple () // +1
14
14
{ // 0
15
15
return 1 ; // 0
16
- } // 0
16
+ }
17
17
18
18
$ var2 = 1 ; // -1
19
19
@@ -31,7 +31,7 @@ function withIf() // +3
31
31
$ var += 2 ; // +1
32
32
} // -1
33
33
return $ var ; // 0
34
- } // 0
34
+ }
35
35
36
36
class MyClass
37
37
{
@@ -48,7 +48,7 @@ function // 0
48
48
if (false ) { // 0
49
49
$ var += 2 ; // +1
50
50
} // -1
51
- } // 0
51
+ }
52
52
public function withForeach () // +2
53
53
{ // 0
54
54
$ var = 1 ; // 0
@@ -73,7 +73,7 @@ public function withForeach() // +2
73
73
{ // 0
74
74
$ var += 2 ; // +4
75
75
} // -4
76
- } // 0
76
+ }
77
77
public function withWhile () // +5
78
78
{ // 0
79
79
$ var = 1 ; // 0
@@ -96,7 +96,7 @@ public function withWhile() // +5
96
96
{ // 0
97
97
++$ var ; // +4
98
98
} // -4
99
- } // 0
99
+ }
100
100
public function withIfElseifElse () // +5
101
101
{ // 0
102
102
$ var = 1 ; // 0
@@ -140,7 +140,7 @@ public function withIfElseifElse() // +5
140
140
{ // 0
141
141
++$ var ; // +12
142
142
} // -12
143
- } // 0
143
+ }
144
144
public function withFor () // +13
145
145
{ // 0
146
146
$ var = 1 ; // 0
@@ -163,7 +163,7 @@ public function withFor() // +13
163
163
{ // 0
164
164
$ var += 2 ; // +4
165
165
} // -4
166
- } // 0
166
+ }
167
167
public function withDoWhile () // +5
168
168
{ // 0
169
169
$ var = 1 ; // 0
@@ -188,7 +188,7 @@ public function withDoWhile() // +5
188
188
$ var // 0
189
189
) // 0
190
190
; // 0
191
- } // 0
191
+ }
192
192
public function withSwitch () // +1
193
193
{ // 0
194
194
$ var = 1 ; // 0
@@ -218,7 +218,7 @@ public function withSwitch() // +1
218
218
default : // -7
219
219
++$ var ; // +8
220
220
endswitch ; // -8
221
- } // 0
221
+ }
222
222
public function withMatch () // +9
223
223
{ // 0
224
224
$ var = 1 ; // 0
@@ -248,5 +248,21 @@ public function withMatch() // +9
248
248
, // -6
249
249
} // 0
250
250
; // 0
251
- } // 0
251
+ }
252
+ public function withReturn () // +7
253
+ { // 0
254
+ $ var = 1 ; // 0
255
+ if (false ) { // 0
256
+ ++$ var ; // +1
257
+ return // 0
258
+ $ var // 0
259
+ ; // 0
260
+ ++$ var ; // +1
261
+ if (false ) { // 0
262
+ ++$ var ; // +1
263
+ } // -1
264
+ } // -2
265
+ return ; // 0
266
+ ++$ var ; // +4
267
+ }
252
268
}
You can’t perform that action at this time.
0 commit comments