Skip to content

Commit

Permalink
Support preg_quote()'d patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Jul 15, 2024
1 parent 1cdc8a0 commit 5da3be5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.11.6"
"phpstan/phpstan": "^1.11.8"
},
"conflict": {
"nette/application": "<2.3.0",
Expand Down
3 changes: 1 addition & 2 deletions src/Type/Nette/StringsMatchDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
return null;
}

$patternType = $scope->getType($patternArg->value);
$flagsArg = $args[2] ?? null;
$flagsType = null;
if ($flagsArg !== null) {
$flagsType = $scope->getType($flagsArg->value);
}

$arrayShape = $this->regexArrayShapeMatcher->matchType($patternType, $flagsType, TrinaryLogic::createYes());
$arrayShape = $this->regexArrayShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createYes(), $scope);
if ($arrayShape === null) {
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Type/Nette/data/strings-match.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ function (string $s): void {

$result = Strings::match($s, '/(foo)(bar)(baz)/');
assertType('array{string, string, string, string}|null', $result);

$result = Strings::match($s, '/(foo)(bar)'. preg_quote($s) .'(baz)/');
assertType('array{string, string, string, string}|null', $result);
};

0 comments on commit 5da3be5

Please sign in to comment.