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)));
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
+
returnself::handleUnion($self, $type);
76
+
}
77
+
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));
80
+
}
81
+
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)));
85
86
}
86
87
87
-
if ('string' === $self->typeName && null === $self->default) {
88
-
thrownewLogicException(\sprintf('The option parameter "$%s" must not have a default of null.', $name));
if (!\in_array($self->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.', $self->name, implode('", "', self::ALLOWED_UNION_TYPES)));
164
+
}
165
+
166
+
if (false !== $self->default) {
167
+
thrownewLogicException(\sprintf('The option parameter "$%s" must have a default value of false.', $self->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,18 @@ public function testNonBinaryInputOptions(array $parameters, array $expected)
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,
268
280
) use ($expected): int {
269
281
$this->assertSame($expected[0], $a);
270
282
$this->assertSame($expected[1], $b);
271
283
$this->assertSame($expected[2], $c);
272
284
$this->assertSame($expected[3], $d);
285
+
$this->assertSame($expected[4], $e);
286
+
$this->assertSame($expected[5], $f);
273
287
274
288
return0;
275
289
});
@@ -279,9 +293,9 @@ public function testNonBinaryInputOptions(array $parameters, array $expected)
0 commit comments