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

X509CertificateLoaderCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 14 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;
15
16
use Jose\Component\KeyManagement\JWKFactory;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Class X509CertificateLoaderCommand.
23
 */
24
final class X509CertificateLoaderCommand extends AbstractGeneratorCommand
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function configure()
30
    {
31
        parent::configure();
32
        $this
33
            ->setName('key:load:x509')
34
            ->setDescription('Load a key from a X.509 certificate file.')
35
            ->addArgument('file', InputArgument::REQUIRED, 'Filename of the X.509 certificate.');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $filename = $input->getArgument('file');
44
        $args = [];
45
        foreach (['use', 'alg'] as $key) {
46
            $value = $input->getOption($key);
47
            if (null !== $value) {
48
                $args[$key] = $value;
49
            }
50
        }
51
52
        $jwk = JWKFactory::createFromCertificateFile($filename, $args);
53
        $this->prepareJsonOutput($input, $output, $jwk);
54
    }
55
}
56