Skip to content

Commit e3c2c0d

Browse files
committed
Nicolas' review
1 parent ba829ad commit e3c2c0d

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/Symfony/Component/Console/Attribute/Argument.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ class Argument
2323
private const ALLOWED_TYPES = ['string', 'bool', 'int', 'float', 'array'];
2424

2525
private string|bool|int|float|array|null $default = null;
26+
private array|\Closure $suggestedValues;
2627
private ?int $mode = null;
2728

2829
/**
2930
* Represents a console command <argument> definition.
3031
*
3132
* If unset, the `name` value will be inferred from the parameter definition.
3233
*
33-
* @param array<string|Suggestion>|callable-string(CompletionInput):list<string|Suggestion> $suggestedValues The values used for input completion
34+
* @param array<string|Suggestion>|callable(CompletionInput):list<string|Suggestion> $suggestedValues The values used for input completion
3435
*/
3536
public function __construct(
3637
public string $name = '',
3738
public string $description = '',
38-
public array|string $suggestedValues = [],
39+
array|callable $suggestedValues = [],
3940
) {
40-
if (\is_string($suggestedValues) && !\is_callable($suggestedValues)) {
41-
throw new \TypeError(\sprintf('Argument 4 passed to "%s()" must be either an array or a callable-string.', __METHOD__));
42-
}
41+
$this->suggestedValues = \is_callable($suggestedValues) ? $suggestedValues(...) : $suggestedValues;
4342
}
4443

4544
/**

src/Symfony/Component/Console/Attribute/Option.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Option
2323
private const ALLOWED_TYPES = ['string', 'bool', 'int', 'float', 'array'];
2424

2525
private string|bool|int|float|array|null $default = null;
26+
private array|\Closure $suggestedValues;
2627
private ?int $mode = null;
2728
private string $typeName = '';
2829
private bool $allowNull = false;
@@ -32,18 +33,16 @@ class Option
3233
*
3334
* If unset, the `name` value will be inferred from the parameter definition.
3435
*
35-
* @param array|string|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
36-
* @param array<string|Suggestion>|callable-string(CompletionInput):list<string|Suggestion> $suggestedValues The values used for input completion
36+
* @param array|string|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
37+
* @param array<string|Suggestion>|callable(CompletionInput):list<string|Suggestion> $suggestedValues The values used for input completion
3738
*/
3839
public function __construct(
3940
public string $name = '',
4041
public array|string|null $shortcut = null,
4142
public string $description = '',
42-
public array|string $suggestedValues = [],
43+
array|callable $suggestedValues = [],
4344
) {
44-
if (\is_string($suggestedValues) && !\is_callable($suggestedValues)) {
45-
throw new \TypeError(\sprintf('Argument 5 passed to "%s()" must be either an array or a callable-string.', __METHOD__));
46-
}
45+
$this->suggestedValues = \is_callable($suggestedValues) ? $suggestedValues(...) : $suggestedValues;
4746
}
4847

4948
/**

src/Symfony/Component/Console/Command/InvokableCommand.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ private function getClosure(callable $code): \Closure
8585
return $code(...);
8686
}
8787

88-
if (null === (new \ReflectionFunction($code))->getClosureThis()) {
89-
set_error_handler(static function () {});
90-
try {
91-
if ($c = \Closure::bind($code, $this->command)) {
92-
$code = $c;
93-
}
94-
} finally {
95-
restore_error_handler();
88+
if (null !== (new \ReflectionFunction($code))->getClosureThis()) {
89+
return $code;
90+
}
91+
92+
set_error_handler(static function () {});
93+
try {
94+
if ($c = \Closure::bind($code, $this->command)) {
95+
$code = $c;
9696
}
97+
} finally {
98+
restore_error_handler();
9799
}
98100

99101
return $code;

0 commit comments

Comments
 (0)