GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AddKeyCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Command\Storage;
6
7
use Damax\Bundle\ApiAuthBundle\Key\Factory;
8
use Damax\Bundle\ApiAuthBundle\Key\Storage\Writer 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 AddKeyCommand extends Command
16
{
17
    protected static $defaultName = 'damax:api-auth:storage:add-key';
18
19
    private $factory;
20
    private $storage;
21
22
    public function __construct(Factory $factory, Storage $storage)
23
    {
24
        parent::__construct();
25
26
        $this->factory = $factory;
27
        $this->storage = $storage;
28
    }
29
30
    protected function configure()
31
    {
32
        $this
33
            ->setDescription('Add api key to storage.')
34
            ->addArgument('identity', InputArgument::REQUIRED, 'Identity of the key.')
35
            ->addArgument('ttl', InputArgument::OPTIONAL, 'Time to live in free form.', '1 week')
36
        ;
37
    }
38
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $io = new SymfonyStyle($input, $output);
42
43
        if (false === $ttl = strtotime($input->getArgument('ttl'), 0)) {
44
            $io->error('Invalid ttl.');
45
46
            return 1;
47
        }
48
49
        $key = $this->factory->createKey($input->getArgument('identity'), $ttl);
50
51
        $this->storage->add($key);
52
53
        $io->success('Key: ' . (string) $key);
54
    }
55
}
56