PublishCheckToken::abortCommandExecution()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Commands\Traits\ChecksEnv;
6
use Acacha\ForgePublish\Commands\Traits\ChecksToken;
7
8
use Acacha\ForgePublish\Commands\Traits\DiesIfNoEnvFileExists;
9
use GuzzleHttp\Client;
10
use Illuminate\Console\Command;
11
12
/**
13
 * Class PublishCheckToken.
14
 *
15
 * @package Acacha\ForgePublish\Commands
16
 */
17
class PublishCheckToken extends Command
18
{
19
    use DiesIfNoEnvFileExists, ChecksEnv, ChecksToken;
20
21
    /**
22
     * API Access Token.
23
     */
24
    protected $token;
25
26
    /**
27
     * API endpoint URL.
28
     */
29
    protected $url;
30
31
    /**
32
     * The name and signature of the console command.
33
     *
34
     * @var string
35
     */
36
    protected $signature = 'publish:check_token {token?}';
37
38
    /**
39
     * The console command description.
40
     *
41
     * @var string
42
     */
43
    protected $description = 'Check token is valid';
44
45
    /**
46
     * Guzzle Http client
47
     *
48
     * @var Client
49
     */
50
    protected $http;
51
52
    /**
53
     * PublishCreateSite constructor.
54
     *
55
     * @param Client $client
56
     */
57
    public function __construct(Client $client)
58
    {
59
        parent::__construct();
60
        $this->http = $client;
61
    }
62
63
    /**
64
     * Execute the console command.
65
     *
66
     */
67
    public function handle()
68
    {
69
        $this->abortCommandExecution();
70
71
        $this->info("Checking if token is valid...");
72
73
        $this->url = $this->checkTokenURL();
74
75
        if ($this->checkToken($this->token)) {
76
            $this->info('Token is valid!');
77
        } else {
78
            $this->error('Token not valid!');
79
        }
80
    }
81
82
    /**
83
     * Abort command execution.
84
     *
85
     */
86
    protected function abortCommandExecution()
87
    {
88
        if (! $this->argument('token')) {
89
            $this->dieIfNoEnvFileIsFound();
90
        }
91
        $this->token = $this->checkEnv('token', 'ACACHA_FORGE_ACCESS_TOKEN', 'argument');
92
    }
93
}
94