Failed Conditions
Push — v7 ( 722dd5...1e67af )
by Florent
03:17
created

AbstractGeneratorCommand::prepareOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
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\Command;
15
16
use Jose\Component\Core\JWKFactory;
17
use Symfony\Component\Console\Input\InputDefinition;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
21
abstract class AbstractGeneratorCommand extends AbstractJsonObjectOutputCommand
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function isEnabled()
27
    {
28
        return class_exists(JWKFactory::class);
29
    }
30
31
    /**
32
     * Configures the current command.
33
     */
34
    protected function configure()
35
    {
36
        parent::configure();
37
        $this
38
            ->setDefinition(
39
                new InputDefinition([
40
                    new InputOption('use', 'u', InputOption::VALUE_OPTIONAL, 'Usage of the key. Must be either "sig" or "enc".'),
41
                    new InputOption('alg', 'a', InputOption::VALUE_OPTIONAL, 'Algorithm for the key.'),
42
                ])
43
            )
44
        ;
45
    }
46
47
    /**
48
     * @param InputInterface $input
49
     *
50
     * @return array
51
     */
52
    protected function getOptions(InputInterface $input): array
53
    {
54
        $args = [];
55
        foreach (['use', 'alg'] as $key) {
56
            $value = $input->getOption($key);
57
            if (null !== $value) {
58
                $args[$key] = $value;
59
            }
60
        }
61
62
        return $args;
63
    }
64
}
65