|
10 | 10 |
|
11 | 11 | use Closure; |
12 | 12 | use Symfony\Component\Console\Command\Command; |
| 13 | +use Symfony\Component\Console\Completion\CompletionInput; |
| 14 | +use Symfony\Component\Console\Completion\CompletionSuggestions; |
| 15 | +use Symfony\Component\Console\Completion\Suggestion; |
13 | 16 | use Symfony\Component\Console\Input\InputDefinition; |
14 | 17 | use Symfony\Component\Console\Input\InputOption; |
15 | | -use function array_key_exists; |
16 | 18 | use function array_map; |
17 | 19 |
|
18 | 20 | /** |
| 21 | + * @psalm-type TInputOption=array{ |
| 22 | + * name: string, |
| 23 | + * shortcut?: string, |
| 24 | + * mode?: int-mask-of<InputOption::*>, |
| 25 | + * description?: string, |
| 26 | + * default?: scalar|array<array-key, mixed>, |
| 27 | + * suggestedValues?: array<array-key, mixed> |
| 28 | + * |Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion>, |
| 29 | + * } |
| 30 | + * |
19 | 31 | * @package App\Command |
20 | 32 | * @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com> |
21 | 33 | */ |
22 | 34 | class HelperConfigure |
23 | 35 | { |
24 | 36 | /** |
25 | | - * @param array<int, array<string, int|string>> $parameters |
| 37 | + * @param list<TInputOption> $parameters |
26 | 38 | */ |
27 | 39 | public static function configure(Command $command, array $parameters): void |
28 | 40 | { |
29 | 41 | // Configure command |
30 | 42 | $command->setDefinition(new InputDefinition(array_map(self::getParameterIterator(), $parameters))); |
31 | 43 | } |
32 | 44 |
|
| 45 | + /** |
| 46 | + * @return Closure(TInputOption):InputOption |
| 47 | + */ |
33 | 48 | private static function getParameterIterator(): Closure |
34 | 49 | { |
35 | | - return static function (array $input): InputOption { |
36 | | - /** @var int-mask-of<InputOption::*>|null $mode */ |
37 | | - $mode = $input['mode']; |
38 | | - |
39 | | - return new InputOption( |
40 | | - (string)$input['name'], |
41 | | - array_key_exists('shortcut', $input) ? (string)$input['shortcut'] : null, |
42 | | - array_key_exists('mode', $input) ? $mode : InputOption::VALUE_OPTIONAL, |
43 | | - array_key_exists('description', $input) ? (string)$input['description'] : '', |
44 | | - array_key_exists('default', $input) ? (string)$input['default'] : null, |
45 | | - ); |
46 | | - }; |
| 50 | + return static fn (array $input): InputOption => new InputOption( |
| 51 | + $input['name'], |
| 52 | + $input['shortcut'] ?? null, |
| 53 | + $input['mode'] ?? InputOption::VALUE_OPTIONAL, |
| 54 | + $input['description'] ?? '', |
| 55 | + $input['default'] ?? null, |
| 56 | + $input['suggestedValues'] ?? [], |
| 57 | + ); |
47 | 58 | } |
48 | 59 | } |
0 commit comments