File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
tests/PHPStan/Rules/Arrays Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 77use PHPStan \Rules \RuleError ;
88use PHPStan \Rules \RuleErrorBuilder ;
99use PHPStan \Rules \RuleLevelHelper ;
10+ use PHPStan \Type \BenevolentUnionType ;
1011use PHPStan \Type \ErrorType ;
1112use PHPStan \Type \Type ;
1213use PHPStan \Type \TypeUtils ;
@@ -68,7 +69,12 @@ static function (Type $type) use ($dimType): bool {
6869 }
6970
7071 if (!$ report && $ this ->reportMaybes ) {
71- foreach (TypeUtils::flattenTypes ($ type ) as $ innerType ) {
72+ if ($ type instanceof BenevolentUnionType) {
73+ $ flattenedTypes = [$ type ];
74+ } else {
75+ $ flattenedTypes = TypeUtils::flattenTypes ($ type );
76+ }
77+ foreach ($ flattenedTypes as $ innerType ) {
7278 if ($ dimType instanceof UnionType) {
7379 if ($ innerType ->hasOffsetValueType ($ dimType )->no ()) {
7480 $ report = true ;
Original file line number Diff line number Diff line change @@ -268,4 +268,14 @@ public function testBug2689(): void
268268 ]);
269269 }
270270
271+ public function testBug5169 (): void
272+ {
273+ $ this ->analyse ([__DIR__ . '/data/bug-5169.php ' ], [
274+ [
275+ 'Cannot access offset mixed on (float|int). ' ,
276+ 29 ,
277+ ],
278+ ]);
279+ }
280+
271281}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Bug5169 ;
4+
5+ class HelloWorld
6+ {
7+ /**
8+ * @param array<mixed> $configs
9+ *
10+ * @return array<mixed>
11+ */
12+ protected function merge (array $ configs ): array
13+ {
14+ $ result = [];
15+ foreach ($ configs as $ config ) {
16+ $ result += $ config ;
17+
18+ foreach ($ config as $ name => $ dto ) {
19+ $ result [$ name ] += $ dto ;
20+ }
21+ }
22+
23+ return $ result ;
24+ }
25+
26+ public function merge2 ($ mixed ): void
27+ {
28+ $ f = $ mixed - $ mixed ;
29+ $ f [$ mixed ] = true ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments