File tree 4 files changed +41
-1
lines changed
tests/PHPStan/Rules/Generators
4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -203,9 +203,11 @@ public function describe(VerbosityLevel $level): string
203
203
{
204
204
$ joinTypes = static function (array $ types ) use ($ level ): string {
205
205
$ typeNames = [];
206
- foreach ($ types as $ type ) {
206
+ foreach ($ types as $ i => $ type ) {
207
207
if ($ type instanceof ClosureType || $ type instanceof CallableType || $ type instanceof TemplateUnionType) {
208
208
$ typeNames [] = sprintf ('(%s) ' , $ type ->describe ($ level ));
209
+ } elseif ($ type instanceof TemplateType && $ i < (count ($ types ) - 1 ) && ($ level ->isTypeOnly () || $ level ->isValue ())) {
210
+ $ typeNames [] = sprintf ('(%s) ' , $ type ->describe ($ level ));
209
211
} elseif ($ type instanceof IntersectionType) {
210
212
$ intersectionDescription = $ type ->describe ($ level );
211
213
if (strpos ($ intersectionDescription , '& ' ) !== false ) {
Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ public function isTypeOnly(): bool
60
60
return $ this ->value === self ::TYPE_ONLY ;
61
61
}
62
62
63
+ public function isValue (): bool
64
+ {
65
+ return $ this ->value === self ::VALUE ;
66
+ }
67
+
63
68
/** @api */
64
69
public static function getRecommendedLevelByType (Type $ acceptingType , ?Type $ acceptedType = null ): self
65
70
{
Original file line number Diff line number Diff line change @@ -59,4 +59,14 @@ public function testRule(): void
59
59
]);
60
60
}
61
61
62
+ public function testBug7484 (): void
63
+ {
64
+ $ this ->analyse ([__DIR__ . '/data/bug-7484.php ' ], [
65
+ [
66
+ 'Generator expects key type K of int|string, (K of int)|string given. ' ,
67
+ 21 ,
68
+ ],
69
+ ]);
70
+ }
71
+
62
72
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug7484 ;
4
+
5
+ /**
6
+ * @template K of int|string
7
+ * @template V
8
+ * @param iterable<K, V> $iterable
9
+ * @return iterable<K, V>
10
+ */
11
+ function changeKeyCase (
12
+ iterable $ iterable ,
13
+ int $ case = CASE_LOWER
14
+ ): iterable {
15
+ $ callable = $ case === CASE_LOWER ? 'strtolower ' : 'strtoupper ' ;
16
+ foreach ($ iterable as $ key => $ value ) {
17
+ if (is_string ($ key )) {
18
+ $ key = $ callable ($ key );
19
+ }
20
+
21
+ yield $ key => $ value ;
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments