RevokeRefreshTokenCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 4
cts 4
cp 1
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 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
    protected static $defaultName = 'gesdinet:jwt:revoke';
26
27 5
    private $refreshTokenManager;
28
29 5
    public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
30 5
    {
31 5
        parent::__construct();
32 5
33 5
        $this->refreshTokenManager = $refreshTokenManager;
34 5
    }
35 5
36
    /**
37
     * @see Command
38
     */
39
    protected function configure()
40 2
    {
41
        $this
42 2
            ->setDescription('Revoke a refresh token')
43
            ->addArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke');
44 2
    }
45 2
46
    /**
47 2
     * @see Command
48 1
     */
49
    protected function execute(InputInterface $input, OutputInterface $output)
50 1
    {
51
        $refreshTokenParam = $input->getArgument('refresh_token');
52
53 1
        $refreshToken = $this->refreshTokenManager->get($refreshTokenParam);
0 ignored issues
show
Bug introduced by
It seems like $refreshTokenParam defined by $input->getArgument('refresh_token') on line 51 can also be of type array<integer,string> or null; however, Gesdinet\JWTRefreshToken...ManagerInterface::get() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
55 1
        if (null === $refreshToken) {
56 1
            $output->writeln(sprintf('<error>Not Found:</error> Refresh Token <comment>%s</comment> doesn\'t exists', $refreshTokenParam));
57
58
            return -1;
59
        }
60
61
        $this->refreshTokenManager->delete($refreshToken);
62
63
        $output->writeln(sprintf('Revoke <comment>%s</comment>', $refreshToken->getRefreshToken()));
64
    }
65
}
66