PublishSites   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B handle() 0 35 4
A serverName() 0 4 1
A abortCommandExecution() 0 4 1
1
<?php
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Commands\Traits\DiesIfEnvVariableIsnotInstalled;
6
use Acacha\ForgePublish\Commands\Traits\ItFetchesServers;
7
use Acacha\ForgePublish\Commands\Traits\ItFetchesSites;
8
use GuzzleHttp\Client;
9
10
use Illuminate\Console\Command;
11
12
/**
13
 * Class PublishSites.
14
 *
15
 * @package Acacha\ForgePublish\Commands
16
 */
17
class PublishSites extends Command
18
{
19
    use ItFetchesSites, ItFetchesServers, DiesIfEnvVariableIsnotInstalled;
20
21
    /**
22
     * The name and signature of the console command.
23
     *
24
     * @var string
25
     */
26
    protected $signature = 'publish:sites {--dump}';
27
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Show sites on current server';
34
35
    /**
36
     * Sites.
37
     *
38
     * @var string
39
     */
40
    protected $sites;
41
42
    /**
43
     * Site names.
44
     *
45
     * @var array
46
     */
47
    protected $site_names;
48
49
    /**
50
     * Server names.
51
     *
52
     * @var Client
53
     */
54
    protected $http;
55
56
    /**
57
     * SaveEnvVariable constructor.
58
     *
59
     */
60
    public function __construct(Client $http)
61
    {
62
        parent::__construct();
63
        $this->http = $http;
64
    }
65
66
    /**
67
     * Handle command.
68
     */
69
    public function handle()
70
    {
71
        $this->abortCommandExecution();
72
73
        $this->sites = $this->fetchSites($server = fp_env('ACACHA_FORGE_SERVER'));
74
        $server_name = $this->serverName($server);
75
        $this->info("Sites on server $server_name ($server)");
76
77
        if ($this->option('dump')) {
78
            dump($this->sites);
79
        }
80
81
        if (empty($this->sites)) {
82
            $this->error('No Sites found.');
83
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
84
        }
85
86
        $headers = ['Id', 'Name','Type','Directory','Status','Repository','RepositoryStatus','QuickDeploy'];
87
88
        $rows = [];
89
        foreach ($this->sites as $site) {
90
            $rows[] = [
91
                $site->id,
92
                $site->name,
93
                $site->projectType,
94
                $site->directory,
95
                $site->status,
96
                $site->repository,
97
                $site->repositoryStatus,
98
                $site->quickDeploy
99
            ];
100
        }
101
102
        $this->table($headers, $rows);
103
    }
104
105
    /**
106
     * Server name.
107
     *
108
     * @param $server
109
     * @return mixed
110
     */
111
    protected function serverName($server)
112
    {
113
        return $this->getForgeName($this->fetchServers(), $server);
114
    }
115
116
    /**
117
     * Abort command execution.
118
     */
119
    protected function abortCommandExecution()
120
    {
121
        $this->dieIfEnvVarIsNotInstalled('ACACHA_FORGE_SERVER');
122
    }
123
}
124