You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -56,18 +57,8 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self
56
57
returnnull;
57
58
}
58
59
59
-
$type = $parameter->getType();
60
60
$name = $parameter->getName();
61
-
62
-
if (!$typeinstanceof \ReflectionNamedType) {
63
-
thrownewLogicException(\sprintf('The parameter "$%s" must have a named type. Untyped, Union or Intersection types are not supported for command options.', $name));
64
-
}
65
-
66
-
$self->typeName = $type->getName();
67
-
68
-
if (!\in_array($self->typeName, self::ALLOWED_TYPES, true)) {
69
-
thrownewLogicException(\sprintf('The type "%s" of parameter "$%s" is not supported as a command option. Only "%s" types are allowed.', $self->typeName, $name, implode('", "', self::ALLOWED_TYPES)));
E29B
70
-
}
61
+
$type = $parameter->getType();
71
62
72
63
if (!$parameter->isDefaultValueAvailable()) {
73
64
thrownewLogicException(\sprintf('The option parameter "$%s" must declare a default value.', $name));
@@ -80,28 +71,37 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self
thrownewLogicException(\sprintf('The option parameter "$%s" must not be nullable when it has a default boolean value.', $name));
74
+
if ($typeinstanceof \ReflectionUnionType) {
75
+
return$self->handleUnion($type);
85
76
}
86
77
87
-
if ('string' === $self->typeName && null === $self->default) {
88
-
thrownewLogicException(\sprintf('The option parameter "$%s" must not have a default of null.', $name));
78
+
if (!$typeinstanceof \ReflectionNamedType) {
79
+
thrownewLogicException(\sprintf('The parameter "$%s" must have a named type. Untyped or Intersection types are not supported for command options.', $name));
89
80
}
90
81
91
-
if ('array' === $self->typeName && $self->allowNull) {
92
-
thrownewLogicException(\sprintf('The option parameter "$%s" must not be nullable.', $name));
82
+
$self->typeName = $type->getName();
83
+
84
+
if (!\in_array($self->typeName, self::ALLOWED_TYPES, true)) {
85
+
thrownewLogicException(\sprintf('The type "%s" of parameter "$%s" is not supported as a command option. Only "%s" types are allowed.', $self->typeName, $name, implode('", "', self::ALLOWED_TYPES)));
if (!\in_array($this->typeName, self::ALLOWED_UNION_TYPES, true)) {
163
+
thrownewLogicException(\sprintf('The union type for parameter "$%s" is not supported as a command option. Only "%s" types are allowed.', $this->name, implode('", "', self::ALLOWED_UNION_TYPES)));
164
+
}
165
+
166
+
if (false !== $this->default) {
167
+
thrownewLogicException(\sprintf('The option parameter "$%s" must have a default value of false.', $this->name));
$this->expectExceptionMessage('The type "object" of parameter "$any" is not supported as a command option. Only "string", "bool", "int", "float", "array" types are allowed.');
@@ -262,14 +272,30 @@ public function testNonBinaryInputOptions(array $parameters, array $e
6D4E
xpected)
262
272
$command = newCommand('foo');
263
273
$command->setCode(function (
264
274
#[Option] string$a = '',
265
-
#[Option] ?string$b = '',
266
-
#[Option] array$c = [],
267
-
#[Option] array$d = ['a', 'b'],
275
+
#[Option] array$b = [],
276
+
#[Option] array$c = ['a', 'b'],
277
+
#[Option] bool|string$d = false,
278
+
#[Option] ?string$e = null,
279
+
#[Option] ?array$f = null,
280
+
#[Option] int$g = 0,
281
+
#[Option] ?int$h = null,
282
+
#[Option] float$i = 0.0,
283
+
#[Option] ?float$j = null,
284
+
#[Option] bool|int$k = false,
285
+
#[Option] bool|float$l = false,
268
286
) use ($expected): int {
269
287
$this->assertSame($expected[0], $a);
270
288
$this->assertSame($expected[1], $b);
271
289
$this->assertSame($expected[2], $c);
272
290
$this->assertSame($expected[3], $d);
291
+
$this->assertSame($expected[4], $e);
292
+
$this->assertSame($expected[5], $f);
293
+
$this->assertSame($expected[6], $g);
294
+
$this->assertSame($expected[7], $h);
295
+
$this->assertSame($expected[8], $i);
296
+
$this->assertSame($expected[9], $j);
297
+
$this->assertSame($expected[10], $k);
298
+
$this->assertSame($expected[11], $l);
273
299
274
300
return0;
275
301
});
@@ -279,9 +305,18 @@ public function testNonBinaryInputOptions(array $parameters, array $expected)
0 commit comments