Skip to content

Commit de4c495

Browse files
committed
feat: migrate validation to private method
1 parent c96736b commit de4c495

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Type/Php/PregSplitDynamicReturnTypeExtension.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
6060
$patternConstantTypes = $patternType->getConstantStrings();
6161
if (count($patternConstantTypes) > 0) {
6262
foreach ($patternConstantTypes as $patternConstantType) {
63-
try {
64-
Strings::match('', $patternConstantType->getValue());
65-
} catch (RegexpException $e) {
63+
if ($this->isValidPattern($patternConstantType->getValue()) === false) {
6664
return new ErrorType();
6765
}
6866
}
@@ -192,4 +190,14 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
192190
private function isPatternOrSubjectEmpty(array $patternConstantArray, array $subjectConstantArray): bool {
193191
return count($patternConstantArray) === 0 || count($subjectConstantArray) === 0;
194192
}
193+
194+
private function isValidPattern(string $pattern): bool
195+
{
196+
try {
197+
Strings::match('', $pattern);
198+
} catch (RegexpException $e) {
199+
return false;
200+
}
201+
return true;
202+
}
195203
}

0 commit comments

Comments
 (0)