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 34
34
final class ConstantResolver
35
35
{
36
36
37
+ public const PHP_MIN_ANALYZABLE_VERSION_ID = 50207 ;
38
+
37
39
/** @var array<string, true> */
38
40
private array $ currentlyResolving = [];
39
41
@@ -141,7 +143,7 @@ public function resolvePredefinedConstant(string $resolvedConstantName): ?Type
141
143
return $ this ->createInteger ($ minRelease , $ maxRelease );
142
144
}
143
145
if ($ resolvedConstantName === 'PHP_VERSION_ID ' ) {
144
- $ minVersion = 50207 ;
146
+ $ minVersion = self :: PHP_MIN_ANALYZABLE_VERSION_ID ;
145
147
$ maxVersion = null ;
146
148
if ($ minPhpVersion !== null ) {
147
149
$ minVersion = max ($ minVersion , $ minPhpVersion ->getVersionId ());
Original file line number Diff line number Diff line change 52
52
use PHPStan \Parser \NewAssignedToPropertyVisitor ;
53
53
use PHPStan \Parser \Parser ;
54
54
use PHPStan \Php \PhpVersion ;
55
+ use PHPStan \Php \PhpVersionFactory ;
55
56
use PHPStan \Php \PhpVersions ;
56
57
use PHPStan \PhpDoc \Tag \TemplateTag ;
57
58
use PHPStan \Reflection \Assertions ;
@@ -6236,7 +6237,17 @@ public function getIterableValueType(Type $iteratee): Type
6236
6237
public function getPhpVersion (): PhpVersions
6237
6238
{
6238
6239
$ 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 ) {
6240
6251
return new PhpVersions ($ constType );
6241
6252
}
6242
6253
Original file line number Diff line number Diff line change @@ -586,4 +586,13 @@ public function testBug12951(): void
586
586
]);
587
587
}
588
588
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
+
589
598
}
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