Skip to content

Commit 0f29634

Browse files
Add more cases
1 parent bc59757 commit 0f29634

File tree

3 files changed

+145
-3
lines changed

3 files changed

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