Skip to content

Commit

Permalink
Add PCRE_VERSION predefined constant
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 authored and ondrejmirtes committed Jun 19, 2024
1 parent f513931 commit 66d7701
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Analyser/ConstantResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ public function resolvePredefinedConstant(string $resolvedConstantName): ?Type
if ($resolvedConstantName === 'OPENSSL_VERSION_NUMBER') {
return IntegerRangeType::fromInterval(1, null);
}

// pcre, https://www.php.net/manual/en/pcre.constants.php
if ($resolvedConstantName === 'PCRE_VERSION') {
return new IntersectionType([
new StringType(),
new AccessoryNonFalsyStringType(),
]);
}

if (in_array($resolvedConstantName, ['STDIN', 'STDOUT', 'STDERR'], true)) {
return new ResourceType();
}
Expand Down
3 changes: 3 additions & 0 deletions tests/PHPStan/Analyser/nsrt/predefined-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
// openssl, https://www.php.net/manual/en/openssl.constants.php
assertType('int<1, max>', OPENSSL_VERSION_NUMBER);

// pcre, https://www.php.net/manual/en/pcre.constants.php
assertType('non-falsy-string', PCRE_VERSION);

// other
assertType('bool', ZEND_DEBUG_BUILD);
assertType('bool', ZEND_THREAD_SAFE);

0 comments on commit 66d7701

Please sign in to comment.