DeactivationByUserCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Garbuzivan\Laraveltokens\Commands;
6
7
use Garbuzivan\Laraveltokens\TokenManager;
8
use Illuminate\Console\Command;
9
use Illuminate\Support\Composer;
10
11
class DeactivationByUserCommand extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'tokens:deactivation-by-user {user_id} {user_type?}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Деактивировать токены пользователя по ID пользователя ' .
26
    '(tokens:deactivation-by-user {user_id} {user_type?})';
27
28
    /**
29
     * The console command signature.
30
     *
31
     * @var string
32
     */
33
    protected $signature = 'tokens:deactivation-by-user {user_id} {user_type?}';
34
35
    /**
36
     * @var Composer
37
     */
38
    public Composer $composer;
39
40
    /**
41
     * @var TokenManager
42
     */
43
    public TokenManager $TokenManager;
44
45
    /**
46
     * Create a new command instance.
47
     */
48
    public function __construct(TokenManager $TokenManager)
49
    {
50
        parent::__construct();
51
        $this->TokenManager = $TokenManager;
52
    }
53
54
    /**
55
     * Execute the command.
56
     *
57
     * @return mixed
58
     */
59
    public function handle()
60
    {
61
        $arguments = $this->arguments();
62
        $user_id = $arguments['user_id'] ? intval($arguments['user_id']) : null;
63
        $user_type = $arguments['user_type'] ?? $this->TokenManager->getDefaultMorph();
64
        if (is_null($user_id) || $user_id < 1) {
65
            $this->line('ID пользователя не введен.');
66
            return 1;
67
        }
68
        $this->TokenManager->deactivationAccessTokenByUser($user_id, $user_type);
69
        $this->line('Токены пользователя деактивированы.');
70
        return 1;
71
    }
72
}
73