|
15 | 15 | use PHPStan\Type\IntegerRangeType; |
16 | 16 | use PHPStan\Type\IntegerType; |
17 | 17 | use PHPStan\Type\NullType; |
18 | | -use PHPStan\Type\Regex\RegexAlternation; |
19 | 18 | use PHPStan\Type\Regex\RegexCapturingGroup; |
20 | 19 | use PHPStan\Type\Regex\RegexExpressionHelper; |
21 | 20 | use PHPStan\Type\Regex\RegexGroupList; |
@@ -117,9 +116,8 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched |
117 | 116 |
|
118 | 117 | $regexGroupList = new RegexGroupList($groupList); |
119 | 118 | $trailingOptionals = $regexGroupList->countTrailingOptionals(); |
120 | | - |
121 | | - $onlyOptionalTopLevelGroupId = $this->getOnlyOptionalTopLevelGroupId($groupList); |
122 | | - $onlyTopLevelAlternation = $this->getOnlyTopLevelAlternation($groupList); |
| 119 | + $onlyOptionalTopLevelGroupId = $regexGroupList->getOnlyOptionalTopLevelGroupId(); |
| 120 | + $onlyTopLevelAlternation = $regexGroupList->getOnlyTopLevelAlternation(); |
123 | 121 | $flags ??= 0; |
124 | 122 |
|
125 | 123 | if ( |
@@ -219,60 +217,6 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched |
219 | 217 | ); |
220 | 218 | } |
221 | 219 |
|
222 | | - /** |
223 | | - * @param array<int, RegexCapturingGroup> $captureGroups |
224 | | - */ |
225 | | - private function getOnlyOptionalTopLevelGroupId(array $captureGroups): ?int |
226 | | - { |
227 | | - $groupIndex = null; |
228 | | - foreach ($captureGroups as $captureGroup) { |
229 | | - if (!$captureGroup->isTopLevel()) { |
230 | | - continue; |
231 | | - } |
232 | | - |
233 | | - if (!$captureGroup->isOptional()) { |
234 | | - return null; |
235 | | - } |
236 | | - |
237 | | - if ($groupIndex !== null) { |
238 | | - return null; |
239 | | - } |
240 | | - |
241 | | - $groupIndex = $captureGroup->getId(); |
242 | | - } |
243 | | - |
244 | | - return $groupIndex; |
245 | | - } |
246 | | - |
247 | | - /** |
248 | | - * @param array<int, RegexCapturingGroup> $captureGroups |
249 | | - */ |
250 | | - private function getOnlyTopLevelAlternation(array $captureGroups): ?RegexAlternation |
251 | | - { |
252 | | - $alternation = null; |
253 | | - foreach ($captureGroups as $captureGroup) { |
254 | | - if (!$captureGroup->isTopLevel()) { |
255 | | - continue; |
256 | | - } |
257 | | - |
258 | | - if (!$captureGroup->inAlternation()) { |
259 | | - return null; |
260 | | - } |
261 | | - |
262 | | - if ($captureGroup->inOptionalQuantification()) { |
263 | | - return null; |
264 | | - } |
265 | | - |
266 | | - if ($alternation === null) { |
267 | | - $alternation = $captureGroup->getAlternation(); |
268 | | - } elseif ($alternation->getId() !== $captureGroup->getAlternation()->getId()) { |
269 | | - return null; |
270 | | - } |
271 | | - } |
272 | | - |
273 | | - return $alternation; |
274 | | - } |
275 | | - |
276 | 220 | /** |
277 | 221 | * @param list<string> $markVerbs |
278 | 222 | */ |
|
0 commit comments