diff --git a/src/Type/Php/PregMatchTypeSpecifyingExtension.php b/src/Type/Php/PregMatchTypeSpecifyingExtension.php index b46758b..487044c 100644 --- a/src/Type/Php/PregMatchTypeSpecifyingExtension.php +++ b/src/Type/Php/PregMatchTypeSpecifyingExtension.php @@ -21,68 +21,65 @@ final class PregMatchTypeSpecifyingExtension implements FunctionTypeSpecifyingExtension, TypeSpecifierAwareExtension { - private TypeSpecifier $typeSpecifier; + private TypeSpecifier $typeSpecifier; - public function __construct( - private RegexArrayShapeMatcher $regexShapeMatcher, - ) - { - } + public function __construct( + private RegexArrayShapeMatcher $regexShapeMatcher, + ) { + } - public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void - { - $this->typeSpecifier = $typeSpecifier; - } + public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void + { + $this->typeSpecifier = $typeSpecifier; + } - public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool - { - return in_array(strtolower($functionReflection->getName()), ['safe\preg_match', 'safe\preg_match_all'], true) && !$context->null(); - } + public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool + { + return in_array(strtolower($functionReflection->getName()), ['safe\preg_match', 'safe\preg_match_all'], true) && !$context->null(); + } - public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes - { - $args = $node->getArgs(); - $patternArg = $args[0] ?? null; - $matchesArg = $args[2] ?? null; - $flagsArg = $args[3] ?? null; + public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes + { + $args = $node->getArgs(); + $patternArg = $args[0] ?? null; + $matchesArg = $args[2] ?? null; + $flagsArg = $args[3] ?? null; - if ( - $patternArg === null || $matchesArg === null - ) { - return new SpecifiedTypes(); - } + if ($patternArg === null || $matchesArg === null + ) { + return new SpecifiedTypes(); + } - $flagsType = null; - if ($flagsArg !== null) { - $flagsType = $scope->getType($flagsArg->value); - } + $flagsType = null; + if ($flagsArg !== null) { + $flagsType = $scope->getType($flagsArg->value); + } - if ($functionReflection->getName() === 'Safe\preg_match') { - $matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); - } else { - $matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); - } - if ($matchedType === null) { - return new SpecifiedTypes(); - } + if ($functionReflection->getName() === 'Safe\preg_match') { + $matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); + } else { + $matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); + } + if ($matchedType === null) { + return new SpecifiedTypes(); + } - $overwrite = false; - if ($context->false()) { - $overwrite = true; - $context = $context->negate(); - } + $overwrite = false; + if ($context->false()) { + $overwrite = true; + $context = $context->negate(); + } - $types = $this->typeSpecifier->create( - $matchesArg->value, - $matchedType, - $context, - $scope, - )->setRootExpr($node); - if ($overwrite) { - $types = $types->setAlwaysOverwriteTypes(); - } - - return $types; - } + $types = $this->typeSpecifier->create( + $matchesArg->value, + $matchedType, + $context, + $scope, + )->setRootExpr($node); + if ($overwrite) { + $types = $types->setAlwaysOverwriteTypes(); + } + return $types; + } }