Skip to content

Commit

Permalink
Fix 7.2/7.3 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jul 13, 2024
1 parent 7de8962 commit 088f752
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/PHPStan/PregMatchFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\Type;
use PhpParser\Node\Arg;
use PHPStan\Type\Php\RegexArrayShapeMatcher;

final class PregMatchFlags
{
static public function getType(?Arg $flagsArg, Scope $scope): ?Type
{
if ($flagsArg === null) {
return new ConstantIntegerType(PREG_UNMATCHED_AS_NULL);
return new ConstantIntegerType(PREG_UNMATCHED_AS_NULL | RegexArrayShapeMatcher::PREG_UNMATCHED_AS_NULL_ON_72_73);
}

$flagsType = $scope->getType($flagsArg->value);
Expand All @@ -29,7 +30,7 @@ static public function getType(?Arg $flagsArg, Scope $scope): ?Type
return null;
}

$internalFlagsTypes[] = new ConstantIntegerType($constantScalarValue | PREG_UNMATCHED_AS_NULL);
$internalFlagsTypes[] = new ConstantIntegerType($constantScalarValue | PREG_UNMATCHED_AS_NULL | RegexArrayShapeMatcher::PREG_UNMATCHED_AS_NULL_ON_72_73);
}
return TypeCombinator::union(...$internalFlagsTypes);
}
Expand Down
28 changes: 14 additions & 14 deletions tests/PHPStanTests/nsrt/preg-match.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ function doMatch(string $s): void
}
assertType('array{}|array{string, string}', $matches);

// if (Preg::match('/Price: (£|€)?\d+/', $s, $matches)) { // temporarily disabled until https://github.com/phpstan/phpstan-src/pull/3229 is released
// assertType('array{0: string, 1: string|null}', $matches);
// } else {
// assertType('array{}', $matches);
// }
// assertType('array{}|array{0: string, 1: string|null}', $matches);
//
// // passing the PREG_UNMATCHED_AS_NULL should change nothing compared to above as it is always set
// if (Preg::match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
// assertType('array{0: string, 1: string|null}', $matches);
// } else {
// assertType('array{}', $matches);
// }
// assertType('array{}|array{0: string, 1: string|null}', $matches);
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches)) {
assertType('array{string, string|null}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, string|null}', $matches);

// passing the PREG_UNMATCHED_AS_NULL should change nothing compared to above as it is always set
if (Preg::match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
assertType('array{string, string|null}', $matches);
} else {
assertType('array{}', $matches);
}
assertType('array{}|array{string, string|null}', $matches);

if (Preg::isMatch('/Price: (?<currency>£|€)\d+/', $s, $matches)) {
assertType('array{0: string, currency: string, 1: string}', $matches);
Expand Down

0 comments on commit 088f752

Please sign in to comment.