2
2
3
3
namespace PHPStan \Rules \Arrays ;
4
4
5
+ use PHPStan \Php \PhpVersion ;
5
6
use PHPStan \Rules \Rule ;
6
7
use PHPStan \Rules \RuleLevelHelper ;
7
8
use PHPStan \Testing \RuleTestCase ;
@@ -21,50 +22,83 @@ protected function getRule(): Rule
21
22
{
22
23
$ ruleLevelHelper = new RuleLevelHelper (self ::createReflectionProvider (), true , false , true , $ this ->checkExplicitMixed , $ this ->checkImplicitMixed , false , true );
23
24
24
- return new InvalidKeyInArrayItemRule ($ ruleLevelHelper );
25
+ return new InvalidKeyInArrayItemRule (
26
+ $ ruleLevelHelper ,
27
+ self ::getContainer ()->getByType (PhpVersion::class),
28
+ );
25
29
}
26
30
27
31
public function testInvalidKey (): void
28
32
{
29
- $ this -> analyse ([ __DIR__ . ' /data/invalid-key-array-item.php ' ], [
33
+ $ errors = [
30
34
[
31
35
'Invalid array key type DateTimeImmutable. ' ,
32
- 13 ,
36
+ 12 ,
33
37
],
34
38
[
35
39
'Invalid array key type array. ' ,
36
- 14 ,
40
+ 13 ,
37
41
],
38
42
[
39
43
'Possibly invalid array key type stdClass|string. ' ,
40
- 15 ,
44
+ 14 ,
41
45
],
42
- ]);
46
+ ];
47
+
48
+ if (PHP_VERSION_ID >= 80100 ) {
49
+ $ errors [] = [
50
+ 'Invalid array key type float. ' ,
51
+ 26 ,
52
+ ];
53
+ }
54
+ if (PHP_VERSION_ID >= 80500 ) {
55
+ $ errors [] = [
56
+ 'Invalid array key type null. ' ,
57
+ 27 ,
58
+ ];
59
+ }
60
+
61
+ $ this ->analyse ([__DIR__ . '/data/invalid-key-array-item.php ' ], $ errors );
43
62
}
44
63
45
64
public function testInvalidMixedKey (): void
46
65
{
47
66
$ this ->checkExplicitMixed = true ;
48
67
$ this ->checkImplicitMixed = true ;
49
68
50
- $ this -> analyse ([ __DIR__ . ' /data/invalid-key-array-item.php ' ], [
69
+ $ errors = [
51
70
[
52
71
'Invalid array key type DateTimeImmutable. ' ,
53
- 13 ,
72
+ 12 ,
54
73
],
55
74
[
56
75
'Invalid array key type array. ' ,
57
- 14 ,
76
+ 13 ,
58
77
],
59
78
[
60
79
'Possibly invalid array key type stdClass|string. ' ,
61
- 15 ,
80
+ 14 ,
62
81
],
63
82
[
64
83
'Possibly invalid array key type mixed. ' ,
65
- 22 ,
84
+ 21 ,
66
85
],
67
- ]);
86
+ ];
87
+
88
+ if (PHP_VERSION_ID >= 80100 ) {
89
+ $ errors [] = [
90
+ 'Invalid array key type float. ' ,
91
+ 26 ,
92
+ ];
93
+ }
94
+ if (PHP_VERSION_ID >= 80500 ) {
95
+ $ errors [] = [
96
+ 'Invalid array key type null. ' ,
97
+ 27 ,
98
+ ];
99
+ }
100
+
101
+ $ this ->analyse ([__DIR__ . '/data/invalid-key-array-item.php ' ], $ errors );
68
102
}
69
103
70
104
public function testInvalidKeyInList (): void
0 commit comments