Failed Conditions
Push — v7 ( 6b9564...530848 )
by Florent
04:53
created

GetThumbprintCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 11 2
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\JWK;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Class GetThumbprintCommand.
24
 */
25
final class GetThumbprintCommand extends AbstractObjectOutputCommand
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        parent::configure();
33
        $this
34
            ->setName('key:thumbprint')
35
            ->setDescription('Get the thumbprint of a JWK key.')
36
            ->addArgument('jwk', InputArgument::REQUIRED, 'The JWK key.')
37
            ->addOption('hash', null, InputOption::VALUE_OPTIONAL, 'The hashing algorithm.', 'sha256');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $jwk = $input->getArgument('jwk');
46
        $hash = $input->getOption('hash');
47
        $json = $this->jsonConverter->decode($jwk);
48
        if (!is_array($json)) {
49
            throw new \InvalidArgumentException('Invalid input.');
50
        }
51
        $key = JWK::create($json);
52
        $this->prepareOutput($input, $output, $key->thumbprint($hash));
53
    }
54
}
55