JKULoaderCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 10 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-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\JKUFactory;
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 JKULoaderCommand extends ObjectOutputCommand
23
{
24
    /**
25
     * @var JKUFactory
26
     */
27
    private $jkuFactory;
28
29
    public function __construct(JKUFactory $jkuFactory, ?string $name = null)
30
    {
31
        $this->jkuFactory = $jkuFactory;
32
        parent::__construct($name);
33
    }
34
35
    protected function configure(): void
36
    {
37
        parent::configure();
38
        $this
39
            ->setName('keyset:load:jku')
40
            ->setDescription('Loads a key set from an url.')
41
            ->setHelp('This command will try to get a key set from an URL. The distant key set is a JWKSet.')
42
            ->addArgument('url', InputArgument::REQUIRED, 'The URL')
43
        ;
44
    }
45
46
    /**
47
     * @throws InvalidArgumentException if the URL is invalid
48
     */
49
    protected function execute(InputInterface $input, OutputInterface $output): ?int
50
    {
51
        $url = $input->getArgument('url');
52
        if (!\is_string($url)) {
53
            throw new InvalidArgumentException('Invalid URL');
54
        }
55
        $result = $this->jkuFactory->loadFromUrl($url);
56
        $this->prepareJsonOutput($input, $output, $result);
57
58
        return 0;
59
    }
60
}
61