@@ -52,17 +52,22 @@ public function enterNode(Node $node): void
5252 if ($ node instanceof Node \Stmt \If_ ||
5353 $ node instanceof Node \Stmt \ElseIf_ ||
5454 $ node instanceof Node \Stmt \Else_ ||
55+ $ node instanceof Node \Stmt \Case_ ||
5556 $ node instanceof Node \Stmt \For_ ||
5657 $ node instanceof Node \Stmt \Foreach_ ||
5758 $ node instanceof Node \Stmt \While_) {
59+ $ incrementNextBranch = false ;
60+
5861 if (isset ($ this ->executableLinesGroupedByBranch [$ node ->getStartLine ()])) {
5962 $ stmtBranch = 1 + $ this ->executableLinesGroupedByBranch [$ node ->getStartLine ()];
6063
6164 if (false !== array_search ($ stmtBranch , $ this ->executableLinesGroupedByBranch , true )) {
62- $ stmtBranch = ++$ this ->nextBranch ;
65+ $ stmtBranch = 1 + $ this ->nextBranch ;
66+ $ incrementNextBranch = true ;
6367 }
6468 } else {
65- $ stmtBranch = ++$ this ->nextBranch ;
69+ $ stmtBranch = 1 + $ this ->nextBranch ;
70+ $ incrementNextBranch = true ;
6671 }
6772
6873 $ endLine = $ node ->getEndLine ();
@@ -89,18 +94,29 @@ public function enterNode(Node $node): void
8994 );
9095 $ contentEnd = $ endLine ;
9196
97+ if ($ node instanceof Node \Stmt \Case_) {
98+ $ contentEnd ++;
99+ }
100+
92101 end ($ node ->stmts );
93102 $ lastNode = current ($ node ->stmts );
94103 reset ($ node ->stmts );
95104
96- if ($ lastNode instanceof Node \Stmt \Nop) {
105+ if (
106+ $ lastNode instanceof Node \Stmt \Nop ||
107+ $ lastNode instanceof Node \Stmt \Break_
108+ ) {
97109 $ contentEnd = $ lastNode ->getEndLine () + 1 ;
98110 }
99111
100112 if (1 > ($ contentEnd - $ contentStart )) {
101113 return ;
102114 }
103115
116+ if ($ incrementNextBranch ) {
117+ $ this ->nextBranch ++;
118+ }
119+
104120 $ this ->setLineBranch (
105121 $ contentStart ,
106122 $ contentEnd - 1 ,
0 commit comments