Completed
Push — master ( efe8c7...564455 )
by Saurabh
01:52
created

RenewCommand::handle()   A

Complexity

Conditions 4
Paths 16

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 16
nop 0
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
1
<?php
2
3
namespace Sausin\Signere\Console;
4
5
use Exception;
6
use Sausin\Signere\ApiKey;
7
use Illuminate\Console\Command;
8
9
class RenewCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'signere:renew {--key= : Specify the key to be renewed}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Renews your primary or secondary signere key';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return void
29
     */
30
    public function handle()
31
    {
32
        $key = $this->option('key') ?: 'primary';
33
        $this->info("Trying to renew your {$key} key...");
34
35
        try {
36
            $apiKey = app()->make(ApiKey::class);
37
38
            if ($this->option('key') === 'secondary') {
39
                $apiKey->renewSecondary(config('signere.secondary_key'));
40
            } else {
41
                $apiKey->renewPrimary(config('signere.primary_key'));
42
            }
43
44
            $this->info("Your {$key} key was renewed!");
45
        } catch (Exception $e) {
46
            $this->error("Renewing failed because: {$e->getMessage()}.");
47
48
            return -1;
49
        }
50
    }
51
}
52