@@ -89,11 +89,12 @@ private function resolveInsertedByKeys(Switch_ $switch) : array
89
89
{
90
90
$ totalKeys = \count ($ switch ->cases );
91
91
$ insertByKeys = [];
92
+ $ appendKey = 0 ;
92
93
foreach ($ switch ->cases as $ key => $ case ) {
93
94
if ($ case ->stmts === []) {
94
95
continue ;
95
96
}
96
- for ($ jumpToKey = $ key + 1 ; $ jumpToKey < $ totalKeys ; ++$ jumpToKey ) {
97
+ for ($ jumpToKey = $ key + 2 ; $ jumpToKey < $ totalKeys ; ++$ jumpToKey ) {
97
98
if (!isset ($ switch ->cases [$ jumpToKey ])) {
98
99
continue ;
99
100
}
@@ -102,9 +103,10 @@ private function resolveInsertedByKeys(Switch_ $switch) : array
102
103
}
103
104
$ nextCase = $ switch ->cases [$ jumpToKey ];
104
105
unset($ switch ->cases [$ jumpToKey ]);
105
- $ insertByKeys [$ key ][] = $ nextCase ;
106
+ $ insertByKeys [$ key + $ appendKey ][] = $ nextCase ;
106
107
$ this ->hasChanged = \true;
107
108
}
109
+ $ appendKey = isset ($ insertByKeys [$ key ]) ? \count ($ insertByKeys [$ key ]) : 0 ;
108
110
}
109
111
return $ insertByKeys ;
110
112
}
@@ -116,9 +118,14 @@ private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
116
118
foreach ($ insertByKeys as $ key => $ insertByKey ) {
117
119
$ nextKey = $ key + 1 ;
118
120
\array_splice ($ switch ->cases , $ nextKey , 0 , $ insertByKey );
119
- for ($ jumpToKey = $ key ; $ jumpToKey < $ key + \count ($ insertByKey ); ++$ jumpToKey ) {
120
- $ switch ->cases [$ jumpToKey ]->stmts = [];
121
+ }
122
+ /** @var Case_|null $previousCase */
123
+ $ previousCase = null ;
124
+ foreach ($ switch ->cases as $ case ) {
125
+ if ($ previousCase instanceof Case_ && $ this ->areSwitchStmtsEqualsAndWithBreak ($ case , $ previousCase )) {
126
+ $ previousCase ->stmts = [];
121
127
}
128
+ $ previousCase = $ case ;
122
129
}
123
130
}
124
131
private function areSwitchStmtsEqualsAndWithBreak (Case_ $ currentCase , Case_ $ nextCase ) : bool
0 commit comments