diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index b143c3e446..faa4cb81a1 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -391,6 +391,9 @@ jobs: cd e2e/composer-version-config composer install ../../bin/phpstan analyze test.php --level=0 + - script: | + cd e2e/composer-version-named-args + ../../bin/phpstan analyze test.php --level=0 steps: - name: "Checkout" diff --git a/e2e/composer-version-named-args/test.php b/e2e/composer-version-named-args/test.php new file mode 100644 index 0000000000..97bae38991 --- /dev/null +++ b/e2e/composer-version-named-args/test.php @@ -0,0 +1,34 @@ += 80400) { + } else { + } + return [ + new Exception(previous: new Exception()), + ]; + } +} + +class HelloWorld2 +{ + /** @return mixed[] */ + public function sayHello(): array|null + { + return [ + PHP_VERSION_ID >= 80400 ? 1 : 0, + new Exception(previous: new Exception()), + ]; + } +} diff --git a/src/Analyser/ConstantResolver.php b/src/Analyser/ConstantResolver.php index 846188b985..52dec8da3b 100644 --- a/src/Analyser/ConstantResolver.php +++ b/src/Analyser/ConstantResolver.php @@ -34,6 +34,8 @@ final class ConstantResolver { + public const PHP_MIN_ANALYZABLE_VERSION_ID = 50207; + /** @var array */ private array $currentlyResolving = []; @@ -141,7 +143,7 @@ public function resolvePredefinedConstant(string $resolvedConstantName): ?Type return $this->createInteger($minRelease, $maxRelease); } if ($resolvedConstantName === 'PHP_VERSION_ID') { - $minVersion = 50207; + $minVersion = self::PHP_MIN_ANALYZABLE_VERSION_ID; $maxVersion = null; if ($minPhpVersion !== null) { $minVersion = max($minVersion, $minPhpVersion->getVersionId()); diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index cdb919da1f..ea86730f30 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -52,6 +52,7 @@ use PHPStan\Parser\NewAssignedToPropertyVisitor; use PHPStan\Parser\Parser; use PHPStan\Php\PhpVersion; +use PHPStan\Php\PhpVersionFactory; use PHPStan\Php\PhpVersions; use PHPStan\PhpDoc\Tag\TemplateTag; use PHPStan\Reflection\Assertions; @@ -6235,8 +6236,10 @@ public function getIterableValueType(Type $iteratee): Type public function getPhpVersion(): PhpVersions { + $overallPhpVersionRange = IntegerRangeType::fromInterval(ConstantResolver::PHP_MIN_ANALYZABLE_VERSION_ID, PhpVersionFactory::MAX_PHP_VERSION); + $constType = $this->getGlobalConstantType(new Name('PHP_VERSION_ID')); - if ($constType !== null) { + if ($constType !== null && !$constType->equals($overallPhpVersionRange)) { return new PhpVersions($constType); }