Skip to content

Commit 30650e6

Browse files
committed
Strings::matchAll() cannot return null
1 parent 14a68a9 commit 30650e6

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

Diff for: src/Type/Nette/StringsMatchAllDynamicReturnTypeExtension.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
use PHPStan\Reflection\MethodReflection;
99
use PHPStan\TrinaryLogic;
1010
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
11-
use PHPStan\Type\NullType;
1211
use PHPStan\Type\Php\RegexArrayShapeMatcher;
1312
use PHPStan\Type\Type;
14-
use PHPStan\Type\TypeCombinator;
1513

1614
class StringsMatchAllDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
1715
{
@@ -48,12 +46,7 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
4846
$flagsType = $scope->getType($flagsArg->value);
4947
}
5048

51-
$arrayShape = $this->regexArrayShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createYes(), $scope);
52-
if ($arrayShape === null) {
53-
return null;
54-
}
55-
56-
return TypeCombinator::union($arrayShape, new NullType());
49+
return $this->regexArrayShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createYes(), $scope);
5750
}
5851

5952
}

Diff for: tests/Type/Nette/data/strings-match.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ function (string $s): void {
2626

2727
function (string $s): void {
2828
$result = Strings::matchAll($s, '/ab(?P<num>\d+)(?P<suffix>ab)?/', PREG_SET_ORDER);
29-
assertType("list<array{0: string, num: numeric-string, 1: numeric-string, suffix?: non-empty-string, 2?: non-empty-string}>|null", $result);
29+
assertType("list<array{0: string, num: numeric-string, 1: numeric-string, suffix?: non-empty-string, 2?: non-empty-string}>", $result);
3030
};
3131

3232
function (string $s): void {
3333
$result = Strings::matchAll($s, '/ab(?P<num>\d+)(?P<suffix>ab)?/', PREG_PATTERN_ORDER);
34-
assertType("array{0: list<string>, num: list<numeric-string>, 1: list<numeric-string>, suffix: list<string>, 2: list<string>}|null", $result);
34+
assertType("array{0: list<string>, num: list<numeric-string>, 1: list<numeric-string>, suffix: list<string>, 2: list<string>}", $result);
3535
};

0 commit comments

Comments
 (0)