Failed Conditions
Push — v7 ( 809898...b3c0a6 )
by Florent
05:05
created

X509CertificateLoaderCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

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