Skip to content

Commit 4384ce7

Browse files
authored
fix: support Array(Tuple) params (#267)
1 parent bff3805 commit 4384ce7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Param/ParamValueConverterRegistry.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ public function __construct()
161161
? $v
162162
: sprintf('[%s]', implode(
163163
',',
164-
array_map(fn (mixed $v) => $this->get($type->params)($v, $type, true), $v),
164+
array_map(function (mixed $v) use ($type) {
165+
$innerType = Type::fromString($type->params);
166+
167+
return $this->get($innerType)($v, $innerType, true);
168+
}, $v),
165169
)),
166170
'Tuple' => function (array|string $v, Type $type) {
167171
if (is_string($v)) {

tests/Param/ParamValueConverterRegistryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public function testConvert(string $type, mixed $value, mixed $expected): void
110110
public static function providerConvert(): Generator
111111
{
112112
yield 'Array' => ['Array(String)', "['foo','bar']", "['foo','bar']"];
113+
yield 'Array LC' => ['Array(LowCardinality(String))', "['foo','bar']", "['foo','bar']"];
113114
yield 'Array (array)' => ['Array(String)', ['foo', 'bar'], "['foo','bar']"];
115+
yield 'Array Tuple' => ['Array(Tuple(String, String))', [['foo', 'bar']], "[('foo','bar')]"];
114116
yield 'Tuple' => ['Tuple(String, Int8)', "('k',1)", "('k',1)"];
115117
yield 'Tuple (array)' => ['Tuple(String, Int8)', ['k', 1], "('k',1)"];
116118

@@ -250,7 +252,7 @@ public static function providerConvert(): Generator
250252
yield 'IPv6' => ['IPv6', '2001:0000:130F:0000:0000:09C0:876A:130B', '2001:0:130f::9c0:876a:130b'];
251253
}
252254

253-
public function testThrowsOnUknownType(): void
255+
public function testThrowsOnUnknownType(): void
254256
{
255257
$registry = new ParamValueConverterRegistry();
256258

0 commit comments

Comments
 (0)