Passed
Push — main ( b73123...a8595a )
by Garbuz
02:48
created

DeleteGlobalTokenByIDCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 1
b 0
f 0
dl 0
loc 58
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 4
A __construct() 0 4 1
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 DeleteGlobalTokenByIDCommand extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'tokens:global-delete-by-id {token_id}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Удалить глобальный токен по ID токена (tokens:global-delete-by-id {token_id})';
26
27
    /**
28
     * The console command signature.
29
     *
30
     * @var string
31
     */
32
    protected $signature = 'tokens:global-delete-by-id {token_id}';
33
34
    /**
35
     * @var Composer
36
     */
37
    public Composer $composer;
38
39
    /**
40
     * @var TokenManager
41
     */
42
    public TokenManager $TokenManager;
43
44
    /**
45
     * Create a new command instance.
46
     */
47
    public function __construct(TokenManager $TokenManager)
48
    {
49
        parent::__construct();
50
        $this->TokenManager = $TokenManager;
51
    }
52
53
    /**
54
     * Execute the command.
55
     *
56
     * @return mixed
57
     */
58
    public function handle()
59
    {
60
        $arguments = $this->arguments();
61
        $token_id = $arguments['token_id'] ? intval($arguments['token_id']) : null;
62
        if (is_null($token_id) || $token_id < 1) {
63
            $this->line('ID токена не введен.');
64
            return 1;
65
        }
66
        $this->TokenManager->deleteGlobalTokenById($token_id);
67
        $this->line('Токен удален.');
68
        return 1;
69
    }
70
}
71