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

RenewCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 21 4
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