Completed
Push — master ( 97f6b5...9ef69c )
by Matze
08:25
created

CreateToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 4
dl 0
loc 47
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A __construct() 0 6 1
A execute() 0 15 1
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\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use BrainExe\Core\Authentication\Token as TokenModel;
11
12
/**
13
 * @CommandAnnotation
14
 */
15
class CreateToken extends Command
16
{
17
    /**
18
     * @var TokenModel
19
     */
20
    private $token;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    protected function configure()
26
    {
27 2
        $this->setName('token:create')
28 2
            ->setDescription('Create user token')
29 2
            ->addArgument('user', InputArgument::REQUIRED)
30 2
            ->addArgument('roles', InputArgument::OPTIONAL);
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
        $roles  = (string)$input->getArgument('roles');
50
51 1
        $token = $this->token->addToken($userId, explode(',', $roles));
52 1
        $output->writeln(
53 1
            sprintf(
54 1
                'Created token %s for user %d with roles: %s',
55
                $token,
56
                $userId,
57 1
                $roles
58
            )
59
        );
60 1
    }
61
}
62