Completed
Pull Request — master (#69)
by
unknown
14:31
created

ClearInvalidRefreshTokensCommand::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.4285
cc 3
eloc 10
nc 4
nop 2
crap 3.009
1
<?php
2
3
/*
4
 * This file is part of the GesdinetJWTRefreshTokenBundle package.
5
 *
6
 * (c) Gesdinet <http://www.gesdinet.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gesdinet\JWTRefreshTokenBundle\Command;
13
14
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Class ClearInvalidRefreshTokensCommand.
21
 */
22
class ClearInvalidRefreshTokensCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * @see Command
26
     */
27 4
    protected function configure()
28
    {
29
        $this
30 4
            ->setName('gesdinet:jwt:clear')
31 4
            ->setDescription('Clear invalid refresh tokens.')
32 4
            ->setDefinition(array(
33 4
                new InputArgument('datetime', InputArgument::OPTIONAL),
34
            ));
35 4
    }
36
37
    /**
38
     * @see Command
39
     */
40 1
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42 1
        $datetime = $input->getArgument('datetime');
43
44 1
        if (null === $datetime) {
45 1
            $datetime = new \DateTime();
46
        } else {
47
            $datetime = new \DateTime($datetime);
48
        }
49
50 1
        $manager = $this->getContainer()->get('gesdinet.jwtrefreshtoken.refresh_token_manager');
51 1
        $revokedTokens = $manager->revokeAllInvalid($datetime);
52
53 1
        foreach ($revokedTokens as $revokedToken) {
54 1
            $output->writeln(sprintf('Revoke <comment>%s</comment>', $revokedToken->getRefreshToken()));
55
        }
56 1
    }
57
}
58