File tree Expand file tree Collapse file tree 4 files changed +81
-2
lines changed
tests/PHPStan/Rules/Classes Expand file tree Collapse file tree 4 files changed +81
-2
lines changed Original file line number Diff line number Diff line change 3434final class ConstantResolver
3535{
3636
37+ public const PHP_MIN_ANALYZABLE_VERSION_ID = 50207 ;
38+
3739 /** @var array<string, true> */
3840 private array $ currentlyResolving = [];
3941
@@ -141,7 +143,7 @@ public function resolvePredefinedConstant(string $resolvedConstantName): ?Type
141143 return $ this ->createInteger ($ minRelease , $ maxRelease );
142144 }
143145 if ($ resolvedConstantName === 'PHP_VERSION_ID ' ) {
144- $ minVersion = 50207 ;
146+ $ minVersion = self :: PHP_MIN_ANALYZABLE_VERSION_ID ;
145147 $ maxVersion = null ;
146148 if ($ minPhpVersion !== null ) {
147149 $ minVersion = max ($ minVersion , $ minPhpVersion ->getVersionId ());
Original file line number Diff line number Diff line change 5252use PHPStan \Parser \NewAssignedToPropertyVisitor ;
5353use PHPStan \Parser \Parser ;
5454use PHPStan \Php \PhpVersion ;
55+ use PHPStan \Php \PhpVersionFactory ;
5556use PHPStan \Php \PhpVersions ;
5657use PHPStan \PhpDoc \Tag \TemplateTag ;
5758use PHPStan \Reflection \Assertions ;
@@ -6236,7 +6237,17 @@ public function getIterableValueType(Type $iteratee): Type
62366237 public function getPhpVersion (): PhpVersions
62376238 {
62386239 $ constType = $ this ->getGlobalConstantType (new Name ('PHP_VERSION_ID ' ));
6239- if ($ constType !== null ) {
6240+
6241+ $ isOverallPhpVersionRange = false ;
6242+ if (
6243+ $ constType instanceof IntegerRangeType
6244+ && $ constType ->getMin () === ConstantResolver::PHP_MIN_ANALYZABLE_VERSION_ID
6245+ && ($ constType ->getMax () === null || $ constType ->getMax () === PhpVersionFactory::MAX_PHP_VERSION )
6246+ ) {
6247+ $ isOverallPhpVersionRange = true ;
6248+ }
6249+
6250+ if ($ constType !== null && !$ isOverallPhpVersionRange ) {
62406251 return new PhpVersions ($ constType );
62416252 }
62426253
Original file line number Diff line number Diff line change @@ -586,4 +586,13 @@ public function testBug12951(): void
586586 ]);
587587 }
588588
589+ public function testNamedArgumentsPhpversion (): void
590+ {
591+ if (PHP_VERSION_ID < 80000 ) {
592+ self ::markTestSkipped ('Test requires PHP 8.0 ' );
593+ }
594+
595+ $ this ->analyse ([__DIR__ . '/data/named-arguments-phpversion.php ' ], []);
596+ }
597+
589598}
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ declare (strict_types = 1 );
4+
5+ namespace NamedArgumentsPhpversion ;
6+
7+ use Exception ;
8+
9+ class HelloWorld
10+ {
11+ /** @return mixed[] */
12+ public function sayHello (): array |null
13+ {
14+ if (PHP_VERSION_ID >= 80400 ) {
15+ } else {
16+ }
17+ return [
18+ new Exception (previous: new Exception ()),
19+ ];
20+ }
21+ }
22+
23+ class HelloWorld2
24+ {
25+ /** @return mixed[] */
26+ public function sayHello (): array |null
27+ {
28+ return [
29+ PHP_VERSION_ID >= 80400 ? 1 : 0 ,
30+ new Exception (previous: new Exception ()),
31+ ];
32+ }
33+ }
34+
35+ class HelloWorld3
36+ {
37+ /** @return mixed[] */
38+ public function sayHello (): array |null
39+ {
40+ return [
41+ PHP_VERSION_ID >= 70400 ? 1 : 0 ,
42+ new Exception (previous: new Exception ()),
43+ ];
44+ }
45+ }
46+
47+ class HelloWorld4
48+ {
49+ /** @return mixed[] */
50+ public function sayHello (): array |null
51+ {
52+ return [
53+ PHP_VERSION_ID < 80000 ? 1 : 0 ,
54+ new Exception (previous: new Exception ()),
55+ ];
56+ }
57+ }
You can’t perform that action at this time.
0 commit comments