ClearInvalidRefreshTokensCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 43
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
A execute() 0 16 3
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 ClearInvalidRefreshTokensCommand extends Command
24
{
25
    protected static $defaultName = 'gesdinet:jwt:clear';
26
27 4
    private $refreshTokenManager;
28
29 4
    public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
30 4
    {
31 4
        parent::__construct();
32 4
33 4
        $this->refreshTokenManager = $refreshTokenManager;
34 4
    }
35 4
36
    /**
37
     * @see Command
38
     */
39
    protected function configure()
40 1
    {
41
        $this
42 1
            ->setDescription('Clear invalid refresh tokens.')
43
            ->addArgument('datetime', InputArgument::OPTIONAL);
44 1
    }
45 1
46 1
    /**
47
     * @see Command
48
     */
49
    protected function execute(InputInterface $input, OutputInterface $output)
50 1
    {
51 1
        $datetime = $input->getArgument('datetime');
52
53 1
        if (null === $datetime) {
54 1
            $datetime = new \DateTime();
55 1
        } else {
56 1
            $datetime = new \DateTime($datetime);
57
        }
58
59
        $revokedTokens = $this->refreshTokenManager->revokeAllInvalid($datetime);
0 ignored issues
show
Unused Code introduced by
The call to RefreshTokenManagerInterface::revokeAllInvalid() has too many arguments starting with $datetime.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
61
        foreach ($revokedTokens as $revokedToken) {
62
            $output->writeln(sprintf('Revoke <comment>%s</comment>', $revokedToken->getRefreshToken()));
63
        }
64
    }
65
}
66