File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
tests/PHPStan/Rules/Functions Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -370,4 +370,12 @@ public function testBug9401(): void
370
370
]);
371
371
}
372
372
373
+ public function testBug7076 (): void
374
+ {
375
+ $ this ->checkExplicitMixed = true ;
376
+ $ this ->checkNullables = true ;
377
+
378
+ $ this ->analyse ([__DIR__ . '/data/bug-7076.php ' ], []);
379
+ }
380
+
373
381
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace Bug7076 ;
4
+
5
+ /**
6
+ * @param array<string, mixed> $param
7
+ * @return array<string, mixed>
8
+ */
9
+ function expectsStringKey (array $ param ): array
10
+ {
11
+ return $ param ;
12
+ }
13
+
14
+ /**
15
+ * @param array<int|string, mixed> $arguments
16
+ * @return array<string, mixed>
17
+ */
18
+ function foo (array $ arguments ): array
19
+ {
20
+ foreach ($ arguments as $ key => $ argument ) {
21
+ if (!is_string ($ key )) {
22
+ throw new \Exception ('Key must be a string ' );
23
+ }
24
+ }
25
+
26
+ return $ arguments ;
27
+ }
28
+
29
+ /**
30
+ * @return array<string, mixed>
31
+ */
32
+ function bar (mixed ...$ arguments ): array
33
+ {
34
+ foreach ($ arguments as $ key => $ argument ) {
35
+ if (!is_string ($ key )) {
36
+ throw new \Exception ('Key must be a string ' );
37
+ }
38
+
39
+ if (is_int ($ key )) {
40
+ echo 'int ' ;
41
+ }
42
+ }
43
+
44
+ return $ arguments ;
45
+ }
46
+
47
+ /**
48
+ * @return array<string, mixed>
49
+ */
50
+ function baz (mixed ...$ arguments ): array
51
+ {
52
+ foreach ($ arguments as $ key => $ argument ) {
53
+ if (is_string ($ key )) {
54
+ continue ;
55
+ }
56
+
57
+ throw new \Exception ('Key must be a string ' );
58
+ }
59
+
60
+ return $ arguments ;
61
+ }
62
+
63
+
You can’t perform that action at this time.
0 commit comments