Test Setup Failed
Pull Request — master (#125)
by Tomas
20:18 queued 02:47
created

RevokeRefreshTokenCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
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\RefreshTokenManagerInterface;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
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 ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
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
            ->setDefinition(array(
44 2
                new InputArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke'),
45 2
            ));
46
    }
47 2
48 1
    /**
49
     * @see Command
50 1
     */
51
    protected function execute(InputInterface $input, OutputInterface $output)
52
    {
53 1
        $refreshTokenParam = $input->getArgument('refresh_token');
54
55 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 53 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...
56 1
57
        if (null === $refreshToken) {
58
            $output->writeln(sprintf('<error>Not Found:</error> Refresh Token <comment>%s</comment> doesn\'t exists', $refreshTokenParam));
59
60
            return -1;
61
        }
62
63
        $this->refreshTokenManager->delete($refreshToken);
64
65
        $output->writeln(sprintf('Revoke <comment>%s</comment>', $refreshToken->getRefreshToken()));
66
    }
67
}
68