ProlongationByIDCommand::handle()   A
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.2222
c 0
b 0
f 0
cc 6
nc 10
nop 0
crap 42
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Garbuzivan\Laraveltokens\Commands;
6
7
use Carbon\Carbon;
8
use Garbuzivan\Laraveltokens\TokenManager;
9
use Illuminate\Console\Command;
10
use Illuminate\Support\Composer;
11
12
class ProlongationByIDCommand extends Command
13
{
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'tokens:prolongation-by-id {token_id} {day?}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Продлить срок действия токена по id токена (tokens:prolongation-by-id {token_id} {day?})';
27
28
    /**
29
     * The console command signature.
30
     *
31
     * @var string
32
     */
33
    protected $signature = 'tokens:prolongation-by-id {token_id} {day?}';
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
        $token_id = $arguments['token_id'] ? intval($arguments['token_id']) : null;
63
        if (is_null($token_id) || $token_id < 1) {
64
            $this->line('ID токена не введен.');
65
            return 1;
66
        }
67
        $expiration = intval($arguments['day']) > 0 ? Carbon::now()->addDays(intval($arguments['day'])) : null;
68
        $this->TokenManager->prolongationAccessTokenById($token_id, $expiration);
69
        $date = is_null($expiration) ? 'навсегда' : 'до ' . $expiration->format('Y-m-d H:i:s');
70
        $this->line('Токен продлен ' . $date . '.');
71
        return 1;
72
    }
73
}
74