ListTokens::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
crap 2
1
<?php
2
3
namespace BrainExe\Core\Authentication\Command;
4
5
use BrainExe\Core\Annotations\Command as CommandAnnotation;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Helper\Table;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use BrainExe\Core\Authentication\Token as TokenModel;
12
13
/**
14
 * @CommandAnnotation
15
 */
16
class ListTokens extends Command
17
{
18
    /**
19
     * @var TokenModel
20
     */
21
    private $token;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 2
    protected function configure()
27
    {
28 2
        $this->setName('token:list')
29 2
            ->setDescription('List user tokens')
30 2
            ->addArgument('user', InputArgument::REQUIRED);
31 2
    }
32
33
    /**
34
     * @param TokenModel $token
35
     */
36 2
    public function __construct(TokenModel $token)
37
    {
38 2
        parent::__construct();
39
40 2
        $this->token = $token;
41 2
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48 1
        $userId = (int)$input->getArgument('user');
49 1
        $tokens = $this->token->getTokensForUser($userId);
50
51 1
        $table = new Table($output);
52 1
        $table->setHeaders(['token', 'roles']);
53
54 1
        foreach ($tokens as $token => $data) {
55 1
            $table->addRow([$token, implode(',', $data)]);
56
        }
57
58 1
        $table->render();
59 1
    }
60
}
61