@@ -123,18 +123,18 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
123
123
$ trailingOptionals ++;
124
124
}
125
125
126
- $ onlyOptionalTopLevelGroupIndex = $ this ->getOnlyOptionalTopLevelGroupIndex ($ groupList );
126
+ $ onlyOptionalTopLevelGroupId = $ this ->getOnlyOptionalTopLevelGroupId ($ groupList );
127
127
$ onlyTopLevelAlternation = $ this ->getOnlyTopLevelAlternation ($ groupList );
128
128
$ flags ??= 0 ;
129
129
130
130
if (
131
131
!$ matchesAll
132
132
&& $ wasMatched ->yes ()
133
- && $ onlyOptionalTopLevelGroupIndex !== null
133
+ && $ onlyOptionalTopLevelGroupId !== null
134
134
) {
135
135
// if only one top level capturing optional group exists
136
136
// we build a more precise tagged union of a empty-match and a match with the group
137
- $ groupList [$ onlyOptionalTopLevelGroupIndex ] = $ groupList [$ onlyOptionalTopLevelGroupIndex ]->forceNonOptional ();
137
+ $ groupList [$ onlyOptionalTopLevelGroupId ] = $ groupList [$ onlyOptionalTopLevelGroupId ]->forceNonOptional ();
138
138
139
139
$ combiType = $ this ->buildArrayType (
140
140
$ groupList ,
@@ -156,7 +156,7 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
156
156
return $ combiType ;
157
157
} elseif (
158
158
!$ matchesAll
159
- && $ onlyOptionalTopLevelGroupIndex === null
159
+ && $ onlyOptionalTopLevelGroupId === null
160
160
&& $ onlyTopLevelAlternation !== null
161
161
&& !$ wasMatched ->no ()
162
162
) {
@@ -228,10 +228,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
228
228
/**
229
229
* @param array<int, RegexCapturingGroup> $captureGroups
230
230
*/
231
- private function getOnlyOptionalTopLevelGroupIndex (array $ captureGroups ): ?int
231
+ private function getOnlyOptionalTopLevelGroupId (array $ captureGroups ): ?int
232
232
{
233
233
$ groupIndex = null ;
234
- foreach ($ captureGroups as $ i => $ captureGroup ) {
234
+ foreach ($ captureGroups as $ captureGroup ) {
235
235
if (!$ captureGroup ->isTopLevel ()) {
236
236
continue ;
237
237
}
@@ -244,7 +244,7 @@ private function getOnlyOptionalTopLevelGroupIndex(array $captureGroups): ?int
244
244
return null ;
245
245
}
246
246
247
- $ groupIndex = $ i ;
247
+ $ groupIndex = $ captureGroup -> getId () ;
248
248
}
249
249
250
250
return $ groupIndex ;
0 commit comments