Skip to content

Commit 6f99f04

Browse files
Add more cases
1 parent bc59757 commit 6f99f04

File tree

4 files changed

+161
-4
lines changed

4 files changed

+161
-4
lines changed

tests/PHPStan/Levels/data/arrayOffsetAccess-4.json

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,110 @@
3333
"message": "Expression \"$a[$implicitlyMixed]\" on a separate line does not do anything.",
3434
"line": 22,
3535
"ignorable": true
36+
},
37+
{
38+
"message": "Expression \"$arrayOrObject[42]\" on a separate line does not do anything.",
39+
"line": 24,
40+
"ignorable": true
41+
},
42+
{
43+
"message": "Expression \"$arrayOrObject[null]\" on a separate line does not do anything.",
44+
"line": 25,
45+
"ignorable": true
46+
},
47+
{
48+
"message": "Expression \"$arrayOrObject[$intOrNull]\" on a separate line does not do anything.",
49+
"line": 27,
50+
"ignorable": true
51+
},
52+
{
53+
"message": "Expression \"$arrayOrObject[$objectOrInt]\" on a separate line does not do anything.",
54+
"line": 28,
55+
"ignorable": true
56+
},
57+
{
58+
"message": "Expression \"$arrayOrObject[$objectOrNull]\" on a separate line does not do anything.",
59+
"line": 29,
60+
"ignorable": true
61+
},
62+
{
63+
"message": "Expression \"$arrayOrObject[$explicitlyMixed]\" on a separate line does not do anything.",
64+
"line": 30,
65+
"ignorable": true
66+
},
67+
{
68+
"message": "Expression \"$arrayOrObject[$implicitlyMixed]\" on a separate line does not do anything.",
69+
"line": 31,
70+
"ignorable": true
71+
},
72+
{
73+
"message": "Expression \"$explicitlyMixed[42]\" on a separate line does not do anything.",
74+
"line": 33,
75+
"ignorable": true
76+
},
77+
{
78+
"message": "Expression \"$explicitlyMixed[null]\" on a separate line does not do anything.",
79+
"line": 34,
80+
"ignorable": true
81+
},
82+
{
83+
"message": "Expression \"$explicitlyMixed[$intOrNull]\" on a separate line does not do anything.",
84+
"line": 36,
85+
"ignorable": true
86+
},
87+
{
88+
"message": "Expression \"$explicitlyMixed[$objectOrInt]\" on a separate line does not do anything.",
89+
"line": 37,
90+
"ignorable": true
91+
},
92+
{
93+
"message": "Expression \"$explicitlyMixed[$objectOrNull]\" on a separate line does not do anything.",
94+
"line": 38,
95+
"ignorable": true
96+
},
97+
{
98+
"message": "Expression \"$explicitlyMixed[$explicitlyMixed]\" on a separate line does not do anything.",
99+
"line": 39,
100+
"ignorable": true
101+
},
102+
{
103+
"message": "Expression \"$explicitlyMixed[$implicitlyMixed]\" on a separate line does not do anything.",
104+
"line": 40,
105+
"ignorable": true
106+
},
107+
{
108+
"message": "Expression \"$implicitlyMixed[42]\" on a separate line does not do anything.",
109+
"line": 42,
110+
"ignorable": true
111+
},
112+
{
113+
"message": "Expression \"$implicitlyMixed[null]\" on a separate line does not do anything.",
114+
"line": 43,
115+
"ignorable": true
116+
},
117+
{
118+
"message": "Expression \"$implicitlyMixed[$intOrNull]\" on a separate line does not do anything.",
119+
"line": 45,
120+
"ignorable": true
121+
},
122+
{
123+
"message": "Expression \"$implicitlyMixed[$objectOrInt]\" on a separate line does not do anything.",
124+
"line": 46,
125+
"ignorable": true
126+
},
127+
{
128+
"message": "Expression \"$implicitlyMixed[$objectOrNull]\" on a separate line does not do anything.",
129+
"line": 47,
130+
"ignorable": true
131+
},
132+
{
133+
"message": "Expression \"$implicitlyMixed[$explicitlyMixed]\" on a separate line does not do anything.",
134+
"line": 48,
135+
"ignorable": true
136+
},
137+
{
138+
"message": "Expression \"$implicitlyMixed[$implicitlyMixed]\" on a separate line does not do anything.",
139+
"line": 49,
140+
"ignorable": true
36141
}
37-
]
142+
]

tests/PHPStan/Levels/data/arrayOffsetAccess-6.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
"line": 13,
55
"ignorable": true
66
},
7+
{
8+
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $arrayOrObject with generic interface ArrayAccess but does not specify its types: TKey, TValue",
9+
"line": 13,
10+
"ignorable": true
11+
},
12+
{
13+
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $arrayOrObject with no value type specified in iterable type array.",
14+
"line": 13,
15+
"ignorable": true
16+
},
717
{
818
"message": "Method Levels\\ArrayOffsetAccess\\Foo::test() has parameter $implicitlyMixed with no type specified.",
919
"line": 13,

tests/PHPStan/Levels/data/arrayOffsetAccess-7.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,20 @@
88
"message": "Possibly invalid array key type object|null.",
99
"line": 20,
1010
"ignorable": true
11+
},
12+
{
13+
"message": "Invalid array key type DateTimeImmutable.",
14+
"line": 26,
15+
"ignorable": true
16+
},
17+
{
18+
"message": "Possibly invalid array key type int|object.",
19+
"line": 28,
20+
"ignorable": true
21+
},
22+
{
23+
"message": "Possibly invalid array key type object|null.",
24+
"line": 29,
25+
"ignorable": true
1126
}
12-
]
27+
]

tests/PHPStan/Levels/data/arrayOffsetAccess.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class Foo {
66
/**
7+
* @param array|\ArrayAccess $arrayOrObject
78
* @param int|null $intOrNull
89
* @param object|int $objectOrInt
910
* @param object|null $objectOrNull
1011
* @param mixed $explicitlyMixed
11-
* @return void
1212
*/
13-
public function test(array $a, $intOrNull, $objectOrInt, $objectOrNull, $explicitlyMixed, $implicitlyMixed)
13+
public function test(array $a, $arrayOrObject, $intOrNull, $objectOrInt, $objectOrNull, $explicitlyMixed, $implicitlyMixed): void
1414
{
1515
$a[42];
1616
$a[null];
@@ -20,5 +20,32 @@ public function test(array $a, $intOrNull, $objectOrInt, $objectOrNull, $explici
2020
$a[$objectOrNull];
2121
$a[$explicitlyMixed];
2222
$a[$implicitlyMixed];
23+
24+
$arrayOrObject[42];
25+
$arrayOrObject[null];
26+
$arrayOrObject[new \DateTimeImmutable()];
27+
$arrayOrObject[$intOrNull];
28+
$arrayOrObject[$objectOrInt];
29+
$arrayOrObject[$objectOrNull];
30+
$arrayOrObject[$explicitlyMixed];
31+
$arrayOrObject[$implicitlyMixed];
32+
33+
$explicitlyMixed[42];
34+
$explicitlyMixed[null];
35+
$explicitlyMixed[new \DateTimeImmutable()];
36+
$explicitlyMixed[$intOrNull];
37+
$explicitlyMixed[$objectOrInt];
38+
$explicitlyMixed[$objectOrNull];
39+
$explicitlyMixed[$explicitlyMixed];
40+
$explicitlyMixed[$implicitlyMixed];
41+
42+
$implicitlyMixed[42];
43+
$implicitlyMixed[null];
44+
$implicitlyMixed[new \DateTimeImmutable()];
45+
$implicitlyMixed[$intOrNull];
46+
$implicitlyMixed[$objectOrInt];
47+
$implicitlyMixed[$objectOrNull];
48+
$implicitlyMixed[$explicitlyMixed];
49+
$implicitlyMixed[$implicitlyMixed];
2350
}
2451
}

0 commit comments

Comments
 (0)