Test Failed
Pull Request — master (#82)
by Aaron
02:58
created

RevokeRefreshTokenCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 2
cbo 6
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 9 1
A execute() 0 16 2
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 Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class ClearInvalidRefreshTokensCommand.
22
 */
23
class RevokeRefreshTokenCommand extends Command
24
{
25
    /**
26
     * @var RefreshTokenManagerInterface
27 5
     */
28
    private $refreshTokenManager;
29 5
30 5
    /**
31 5
     * ClearInvalidRefreshTokensCommand constructor.
32 5
     *
33 5
     * @param RefreshTokenManagerInterface $refreshTokenManager
34 5
     */
35 5
    public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
36
    {
37
        $this->refreshTokenManager = $refreshTokenManager;
38
    }
39
40 2
    /**
41
     * @see Command
42 2
     */
43
    protected function configure()
44 2
    {
45 2
        $this
46
            ->setName('gesdinet:jwt:revoke')
47 2
            ->setDescription('Revoke a refresh token')
48 1
            ->setDefinition(array(
49
                new InputArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke'),
50 1
            ));
51
    }
52
53 1
    /**
54
     * @see Command
55 1
     */
56 1
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        $refreshTokenParam = $input->getArgument('refresh_token');
59
60
        $refreshToken = $this->refreshTokenManager->get($refreshTokenParam);
61
62
        if (null === $refreshToken) {
63
            $output->writeln(sprintf('<error>Not Found:</error> Refresh Token <comment>%s</comment> doesn\'t exists', $refreshTokenParam));
64
65
            return -1;
66
        }
67
68
        $this->refreshTokenManager->delete($refreshToken);
69
70
        $output->writeln(sprintf('Revoke <comment>%s</comment>', $refreshToken->getRefreshToken()));
71
    }
72
}
73