RsaKeyGeneratorCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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 InvalidArgumentException;
17
use Jose\Component\KeyManagement\JWKFactory;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
final class RsaKeyGeneratorCommand extends GeneratorCommand
23
{
24
    protected function configure(): void
25
    {
26
        parent::configure();
27
        $this
28
            ->setName('key:generate:rsa')
29
            ->setDescription('Generate a RSA key (JWK format)')
30
            ->addArgument('size', InputArgument::REQUIRED, 'Key size.')
31
        ;
32
    }
33
34
    /**
35
     * @throws InvalidArgumentException if the key size is invalid
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output): ?int
38
    {
39
        $size = (int) $input->getArgument('size');
40
        $args = $this->getOptions($input);
41
        if ($size < 1) {
42
            throw new InvalidArgumentException('Invalid size');
43
        }
44
45
        $jwk = JWKFactory::createRSAKey($size, $args);
46
        $this->prepareJsonOutput($input, $output, $jwk);
47
48
        return 0;
49
    }
50
}
51