Skip to content

Commit 539f006

Browse files
authored
Merge pull request #3054 from tarlepp/buf/fix-mode-option
Bug: Fixed mode option from user/group console commands
2 parents 81937fe + 634f8d2 commit 539f006

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

src/Command/ApiKey/CreateApiKeyCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Throwable;
2828

2929
/**
30+
* @psalm-import-type TInputOption from HelperConfigure
31+
*
3032
* @package App\Command\ApiKey
3133
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
3234
*/
@@ -42,7 +44,7 @@ class CreateApiKeyCommand extends Command
4244
final public const string NAME = 'api-key:create';
4345

4446
/**
45-
* @var array<int, array<string, string>>
47+
* @var list<TInputOption>
4648
*/
4749
private static array $commandParameters = [
4850
[

src/Command/HelperConfigure.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,50 @@
1010

1111
use Closure;
1212
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;
1316
use Symfony\Component\Console\Input\InputDefinition;
1417
use Symfony\Component\Console\Input\InputOption;
15-
use function array_key_exists;
1618
use function array_map;
1719

1820
/**
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+
*
1931
* @package App\Command
2032
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
2133
*/
2234
class HelperConfigure
2335
{
2436
/**
25-
* @param array<int, array<string, int|string>> $parameters
37+
* @param list<TInputOption> $parameters
2638
*/
2739
public static function configure(Command $command, array $parameters): void
2840
{
2941
// Configure command
3042
$command->setDefinition(new InputDefinition(array_map(self::getParameterIterator(), $parameters)));
3143
}
3244

45+
/**
46+
* @return Closure(TInputOption):InputOption
47+
*/
3348
private static function getParameterIterator(): Closure
3449
{
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+
);
4758
}
4859
}

src/Command/User/CreateUserCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Throwable;
2828

2929
/**
30+
* @psalm-import-type TInputOption from HelperConfigure
31+
*
3032
* @package App\Command\User
3133
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
3234
*/
@@ -45,7 +47,7 @@ class CreateUserCommand extends Command
4547
private const string PARAMETER_DESCRIPTION = 'description';
4648

4749
/**
48-
* @var array<int, array<string, string>>
50+
* @var list<TInputOption>
4951
*/
5052
private static array $commandParameters = [
5153
[

src/Command/User/CreateUserGroupCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use Throwable;
2727

2828
/**
29+
* @psalm-import-type TInputOption from HelperConfigure
30+
*
2931
* @package App\Command\User
3032
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
3133
*/
@@ -41,7 +43,7 @@ class CreateUserGroupCommand extends Command
4143
final public const string NAME = 'user:create-group';
4244

4345
/**
44-
* @var array<int, array<string, string>>
46+
* @var list<TInputOption>
4547
*/
4648
private static array $commandParameters = [
4749
[

0 commit comments

Comments
 (0)