Skip to content

Commit 6b81aaa

Browse files
committed
Iterable printing improvements
1 parent 7f9e8ef commit 6b81aaa

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/ShowTypePrettier.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private static function atomic(Atomic $atomic, Codebase $codebase, int $level):
3030
return match (true) {
3131
$atomic instanceof Atomic\TList => self::list($atomic, $codebase, $level),
3232
$atomic instanceof Atomic\TArray => self::array($atomic, $codebase, $level),
33+
$atomic instanceof Atomic\TIterable => self::iterable($atomic, $codebase, $level),
3334
$atomic instanceof Atomic\TClosure => self::callable($atomic, $codebase, $level),
3435
$atomic instanceof Atomic\TCallable => self::callable($atomic, $codebase, $level),
3536
$atomic instanceof Atomic\TClassString => self::classString($atomic, $codebase, $level),
@@ -40,6 +41,14 @@ private static function atomic(Atomic $atomic, Codebase $codebase, int $level):
4041
};
4142
}
4243

44+
private static function iterable(Atomic\TIterable $atomic, Codebase $codebase, int $level): string
45+
{
46+
$key = self::union($atomic->type_params[0], $codebase, $level);
47+
$val = self::union($atomic->type_params[1], $codebase, $level);
48+
49+
return "iterable<TKey: {$key}, TValue: $val>";
50+
}
51+
4352
private static function classString(Atomic\TClassString $atomic, Codebase $codebase, int $level): string
4453
{
4554
return null !== $atomic->as_type
@@ -57,23 +66,21 @@ private static function templateParam(Atomic\TTemplateParam $atomic, Codebase $c
5766

5867
private static function array(Atomic\TArray $atomic, Codebase $codebase, int $level): string
5968
{
60-
$types = implode(', ', array_map(
61-
fn(Union $param) => self::union($param, $codebase, $level),
62-
$atomic->type_params
63-
));
69+
$key = self::union($atomic->type_params[0], $codebase, $level);
70+
$val = self::union($atomic->type_params[1], $codebase, $level);
6471

6572
return $atomic instanceof Atomic\TNonEmptyArray
66-
? "non-empty-array<{$types}>"
67-
: "array<{$types}>";
73+
? "non-empty-array<TKey: {$key}, TValue: {$val}>"
74+
: "array<TKey: {$key}, TValue: $val>";
6875
}
6976

7077
private static function list(Atomic\TList $atomic, Codebase $codebase, int $level): string
7178
{
7279
$type = self::union($atomic->type_param, $codebase, $level);
7380

7481
return $atomic instanceof Atomic\TNonEmptyList
75-
? "non-empty-list<{$type}>"
76-
: "list<{$type}>";
82+
? "non-empty-list<TValue: {$type}>"
83+
: "list<TValue: {$type}>";
7784
}
7885

7986
private static function callable(Atomic\TClosure|Atomic\TCallable $atomic, Codebase $codebase, int $level): string

0 commit comments

Comments
 (0)