Skip to content

Commit 5da3be5

Browse files
staabmondrejmirtes
authored andcommitted
Support preg_quote()'d patterns
1 parent 1cdc8a0 commit 5da3be5

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.2 || ^8.0",
10-
"phpstan/phpstan": "^1.11.6"
10+
"phpstan/phpstan": "^1.11.8"
1111
},
1212
"conflict": {
1313
"nette/application": "<2.3.0",

src/Type/Nette/StringsMatchDynamicReturnTypeExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
4242
return null;
4343
}
4444

45-
$patternType = $scope->getType($patternArg->value);
4645
$flagsArg = $args[2] ?? null;
4746
$flagsType = null;
4847
if ($flagsArg !== null) {
4948
$flagsType = $scope->getType($flagsArg->value);
5049
}
5150

52-
$arrayShape = $this->regexArrayShapeMatcher->matchType($patternType, $flagsType, TrinaryLogic::createYes());
51+
$arrayShape = $this->regexArrayShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createYes(), $scope);
5352
if ($arrayShape === null) {
5453
return null;
5554
}

tests/Type/Nette/data/strings-match.php

+3
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ function (string $s): void {
1818

1919
$result = Strings::match($s, '/(foo)(bar)(baz)/');
2020
assertType('array{string, string, string, string}|null', $result);
21+
22+
$result = Strings::match($s, '/(foo)(bar)'. preg_quote($s) .'(baz)/');
23+
assertType('array{string, string, string, string}|null', $result);
2124
};

0 commit comments

Comments
 (0)