LookupKeyCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Command\Storage;
6
7
use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound;
8
use Damax\Bundle\ApiAuthBundle\Key\Storage\Reader as Storage;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
final class LookupKeyCommand extends Command
16
{
17
    protected static $defaultName = 'damax:api-auth:storage:lookup-key';
18
19
    private $storage;
20
21
    public function __construct(Storage $storage)
22
    {
23
        parent::__construct();
24
25
        $this->storage = $storage;
26
    }
27
28
    protected function configure()
29
    {
30
        $this
31
            ->setDescription('Lookup api key in storage.')
32
            ->addArgument('key', InputArgument::REQUIRED, 'Api key.')
33
        ;
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $io = new SymfonyStyle($input, $output);
39
40
        try {
41
            $key = $this->storage->get((string) $input->getArgument('key'));
42
        } catch (KeyNotFound $e) {
43
            $io->error('Key not found.');
44
45
            return 1;
46
        }
47
48
        $io->writeln('');
49
        $io->table([], [
50
            ['Key', (string) $key],
51
            ['Identity', $key->identity()],
52
            ['TTL', $key->ttl()],
53
        ]);
54
    }
55
}
56