HelperConfigure   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A getParameterIterator() 0 8 5
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Command/HelperConfigure.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Command;
10
11
use Closure;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputDefinition;
14
use Symfony\Component\Console\Input\InputOption;
15
use function array_key_exists;
16
use function array_map;
17
18
/**
19
 * Class HelperConfigure
20
 *
21
 * @package App\Command
22
 * @author TLe, Tarmo Leppänen <[email protected]>
23
 */
24
class HelperConfigure
25
{
26
    /**
27
     * @param array<int, array<string, int|string>> $parameters
28
     */
29
    public static function configure(Command $command, array $parameters): void
30
    {
31
        // Configure command
32
        $command->setDefinition(new InputDefinition(array_map(self::getParameterIterator(), $parameters)));
33
    }
34
35
    private static function getParameterIterator(): Closure
36
    {
37
        return static fn (array $input): InputOption => new InputOption(
38
            (string)$input['name'],
39
            array_key_exists('shortcut', $input) ? (string)$input['shortcut'] : null,
40
            array_key_exists('mode', $input) ? (int)$input['mode'] : InputOption::VALUE_OPTIONAL,
41
            array_key_exists('description', $input) ? (string)$input['description'] : '',
42
            array_key_exists('default', $input) ? (string)$input['default'] : null,
43
        );
44
    }
45
}
46