Skip to content

Commit 8232f00

Browse files
committed
Ask runtime version about PREG_UNMATCHED_AS_NULL compatibility
1 parent 7fab7a5 commit 8232f00

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

src/Php/PhpVersion.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,4 @@ public function supportsNeverReturnTypeInArrowFunction(): bool
287287
return $this->versionId >= 80200;
288288
}
289289

290-
// see https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.pcre
291-
public function returnsPregUnmatchedCapturingGroups(): bool
292-
{
293-
// When PREG_UNMATCHED_AS_NULL mode is used, trailing unmatched capturing groups will now also be set to null (or [null, -1] if offset capture is enabled).
294-
// This means that the size of the $matches will always be the same.
295-
return $this->versionId >= 70400;
296-
}
297-
298290
}

src/Type/Php/RegexArrayShapeMatcher.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Hoa\File\Read;
1010
use Nette\Utils\RegexpException;
1111
use Nette\Utils\Strings;
12-
use PHPStan\Php\PhpVersion;
1312
use PHPStan\TrinaryLogic;
1413
use PHPStan\Type\Constant\ConstantArrayType;
1514
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
@@ -26,6 +25,7 @@
2625
use function is_int;
2726
use function is_string;
2827
use function str_contains;
28+
use const PHP_VERSION_ID;
2929
use const PREG_OFFSET_CAPTURE;
3030
use const PREG_UNMATCHED_AS_NULL;
3131

@@ -37,21 +37,16 @@ final class RegexArrayShapeMatcher
3737

3838
private static ?Parser $parser = null;
3939

40-
public function __construct(
41-
private PhpVersion $phpVersion,
42-
)
43-
{
44-
}
45-
4640
public function matchType(Type $patternType, ?Type $flagsType, TrinaryLogic $wasMatched): ?Type
4741
{
4842
if ($wasMatched->no()) {
4943
return new ConstantArrayType([], []);
5044
}
5145

52-
if (
53-
!$this->phpVersion->returnsPregUnmatchedCapturingGroups()
54-
) {
46+
if (PHP_VERSION_ID < 70400) {
47+
// see https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.pcre
48+
// When PREG_UNMATCHED_AS_NULL mode is used, trailing unmatched capturing groups will now also be set to null (or [null, -1] if offset capture is enabled).
49+
// This means that the size of the $matches will always be the same.
5550
return null;
5651
}
5752

0 commit comments

Comments
 (0)