|
21 | 21 | final class PregMatchTypeSpecifyingExtension implements FunctionTypeSpecifyingExtension, TypeSpecifierAwareExtension
|
22 | 22 | {
|
23 | 23 |
|
24 |
| - private TypeSpecifier $typeSpecifier; |
| 24 | + private TypeSpecifier $typeSpecifier; |
25 | 25 |
|
26 |
| - public function __construct( |
27 |
| - private RegexArrayShapeMatcher $regexShapeMatcher, |
28 |
| - ) |
29 |
| - { |
30 |
| - } |
| 26 | + public function __construct( |
| 27 | + private RegexArrayShapeMatcher $regexShapeMatcher, |
| 28 | + ) { |
| 29 | + } |
31 | 30 |
|
32 |
| - public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void |
33 |
| - { |
34 |
| - $this->typeSpecifier = $typeSpecifier; |
35 |
| - } |
| 31 | + public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void |
| 32 | + { |
| 33 | + $this->typeSpecifier = $typeSpecifier; |
| 34 | + } |
36 | 35 |
|
37 |
| - public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool |
38 |
| - { |
39 |
| - return in_array(strtolower($functionReflection->getName()), ['safe\preg_match', 'safe\preg_match_all'], true) && !$context->null(); |
40 |
| - } |
| 36 | + public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool |
| 37 | + { |
| 38 | + return in_array(strtolower($functionReflection->getName()), ['safe\preg_match', 'safe\preg_match_all'], true) && !$context->null(); |
| 39 | + } |
41 | 40 |
|
42 |
| - public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes |
43 |
| - { |
44 |
| - $args = $node->getArgs(); |
45 |
| - $patternArg = $args[0] ?? null; |
46 |
| - $matchesArg = $args[2] ?? null; |
47 |
| - $flagsArg = $args[3] ?? null; |
| 41 | + public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes |
| 42 | + { |
| 43 | + $args = $node->getArgs(); |
| 44 | + $patternArg = $args[0] ?? null; |
| 45 | + $matchesArg = $args[2] ?? null; |
| 46 | + $flagsArg = $args[3] ?? null; |
48 | 47 |
|
49 |
| - if ( |
50 |
| - $patternArg === null || $matchesArg === null |
51 |
| - ) { |
52 |
| - return new SpecifiedTypes(); |
53 |
| - } |
| 48 | + if ($patternArg === null || $matchesArg === null |
| 49 | + ) { |
| 50 | + return new SpecifiedTypes(); |
| 51 | + } |
54 | 52 |
|
55 |
| - $flagsType = null; |
56 |
| - if ($flagsArg !== null) { |
57 |
| - $flagsType = $scope->getType($flagsArg->value); |
58 |
| - } |
| 53 | + $flagsType = null; |
| 54 | + if ($flagsArg !== null) { |
| 55 | + $flagsType = $scope->getType($flagsArg->value); |
| 56 | + } |
59 | 57 |
|
60 |
| - if ($functionReflection->getName() === 'Safe\preg_match') { |
61 |
| - $matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); |
62 |
| - } else { |
63 |
| - $matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); |
64 |
| - } |
65 |
| - if ($matchedType === null) { |
66 |
| - return new SpecifiedTypes(); |
67 |
| - } |
| 58 | + if ($functionReflection->getName() === 'Safe\preg_match') { |
| 59 | + $matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); |
| 60 | + } else { |
| 61 | + $matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope); |
| 62 | + } |
| 63 | + if ($matchedType === null) { |
| 64 | + return new SpecifiedTypes(); |
| 65 | + } |
68 | 66 |
|
69 |
| - $overwrite = false; |
70 |
| - if ($context->false()) { |
71 |
| - $overwrite = true; |
72 |
| - $context = $context->negate(); |
73 |
| - } |
| 67 | + $overwrite = false; |
| 68 | + if ($context->false()) { |
| 69 | + $overwrite = true; |
| 70 | + $context = $context->negate(); |
| 71 | + } |
74 | 72 |
|
75 |
| - $types = $this->typeSpecifier->create( |
76 |
| - $matchesArg->value, |
77 |
| - $matchedType, |
78 |
| - $context, |
79 |
| - $scope, |
80 |
| - )->setRootExpr($node); |
81 |
| - if ($overwrite) { |
82 |
| - $types = $types->setAlwaysOverwriteTypes(); |
83 |
| - } |
84 |
| - |
85 |
| - return $types; |
86 |
| - } |
| 73 | + $types = $this->typeSpecifier->create( |
| 74 | + $matchesArg->value, |
| 75 | + $matchedType, |
| 76 | + $context, |
| 77 | + $scope, |
| 78 | + )->setRootExpr($node); |
| 79 | + if ($overwrite) { |
| 80 | + $types = $types->setAlwaysOverwriteTypes(); |
| 81 | + } |
87 | 82 |
|
| 83 | + return $types; |
| 84 | + } |
88 | 85 | }
|
0 commit comments