Completed
Pull Request — master (#77)
by Evgeny
11:21 queued 06:43
created

ClearInvalidRefreshTokensCommand::__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\Doctrine\RefreshTokenManager;
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 ClearInvalidRefreshTokensCommand extends Command
25
{
26
    /**
27 4
     * @var RefreshTokenManager
28
     */
29 4
    private $refreshTokenManager;
30 4
31 4
    public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
32 4
    {
33 4
        parent::__construct();
34 4
        $this->refreshTokenManager = $refreshTokenManager;
0 ignored issues
show
Documentation Bug introduced by
$refreshTokenManager is of type object<Gesdinet\JWTRefre...hTokenManagerInterface>, but the property $refreshTokenManager was declared to be of type object<Gesdinet\JWTRefre...ne\RefreshTokenManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
35 4
    }
36
37
    protected function configure(): void
38
    {
39
        $this
40 1
            ->setName('gesdinet:jwt:clear')
41
            ->setDescription('Clear invalid refresh tokens.')
42 1
            ->setDefinition(
43
                [
44 1
                    new InputArgument('datetime', InputArgument::OPTIONAL),
45 1
                ]
46 1
            );
47
    }
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);
60
61
        foreach ($revokedTokens as $revokedToken) {
62
            $output->writeln(sprintf('Revoke <comment>%s</comment>', $revokedToken->getRefreshToken()));
63
        }
64
    }
65
}
66