Test Failed
Pull Request — master (#77)
by Evgeny
23:11
created

RevokeRefreshTokenCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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\RefreshTokenInterface;
15
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Class ClearInvalidRefreshTokensCommand.
23
 */
24
class RevokeRefreshTokenCommand extends Command
25
{
26
    /**
27 5
     * @var RefreshTokenManagerInterface
28
     */
29 5
    private $refreshTokenManager;
30 5
31 5
    public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
32 5
    {
33 5
        parent::__construct();
34 5
        $this->refreshTokenManager = $refreshTokenManager;
35 5
    }
36
37
    protected function configure(): void
38
    {
39
        $this
40 2
            ->setName('gesdinet:jwt:revoke')
41
            ->setDescription('Revoke a refresh token')
42 2
            ->setDefinition(
43
                [
44 2
                    new InputArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke'),
45 2
                ]
46
            );
47 2
    }
48 1
49
    protected function execute(InputInterface $input, OutputInterface $output): int
50 1
    {
51
        $refreshTokenParam = $input->getArgument('refresh_token');
52
53 1
        $refreshToken = $this->refreshTokenManager->get($refreshTokenParam);
54
55 1
        if ($refreshToken instanceof RefreshTokenInterface) {
56 1
            $this->refreshTokenManager->delete($refreshToken);
57
58
            $output->writeln(sprintf('Revoke <comment>%s</comment>', $refreshToken->getRefreshToken()));
59
60
            return 0;
61
        } else {
62
            $output->writeln(
63
                sprintf(
64
                    '<error>Not Found:</error> Refresh Token <comment>%s</comment> doesn\'t exists',
65
                    $refreshTokenParam
66
                )
67
            );
68
69
            return -1;
70
        }
71
    }
72
}
73