Failed Conditions
Push — v7 ( 12d27f...276ae4 )
by Florent
03:49
created

AbstractGeneratorCommand::getOptions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Console;
15
16
use Jose\Component\KeyManagement\JWKFactory;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
20
/**
21
 * Class AbstractGeneratorCommand.
22
 */
23
abstract class AbstractGeneratorCommand extends AbstractObjectOutputCommand
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function isEnabled()
29
    {
30
        return class_exists(JWKFactory::class);
31
    }
32
33
    /**
34
     * Configures the current command.
35
     */
36
    protected function configure()
37
    {
38
        parent::configure();
39
        $this
40
            ->addOption('use', 'u', InputOption::VALUE_OPTIONAL, 'Usage of the key. Must be either "sig" or "enc".')
41
            ->addOption('alg', 'a', InputOption::VALUE_OPTIONAL, 'Algorithm for the key.')
42
        ;
43
    }
44
45
    /**
46
     * @param InputInterface $input
47
     *
48
     * @return array
49
     */
50
    protected function getOptions(InputInterface $input): array
51
    {
52
        $args = [];
53
        foreach (['use', 'alg'] as $key) {
54
            $value = $input->getOption($key);
55
            if (null !== $value) {
56
                $args[$key] = $value;
57
            }
58
        }
59
60
        return $args;
61
    }
62
}
63