PublishServer::before()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 154.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Commands\Traits\ItFetchesServers;
6
use GuzzleHttp\Client;
7
8
/**
9
 * Class PublishServer.
10
 *
11
 * @package Acacha\ForgePublish\Commands
12
 */
13
class PublishServer extends SaveEnvVariable
14
{
15
    use ItFetchesServers;
16
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'publish:server {server?}';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Save acacha forge server';
30
31
    /**
32
     * Servers.
33
     *
34
     * @var array
35
     */
36
    protected $servers;
37
38
    /**
39
     * Server.
40
     *
41
     * @var string
42
     */
43
    protected $server;
44
45
    /**
46
     * Server names.
47
     *
48
     * @var array
49
     */
50
    protected $server_names;
51
52
    /**
53
     * Server names.
54
     *
55
     * @var array
56
     */
57
    protected $server_ids;
58
59
    /**
60
     * Server names.
61
     *
62
     * @var Client
63
     */
64
    protected $http;
65
66
    /**
67
     * SaveEnvVariable constructor.
68
     *
69
     */
70
    public function __construct(Client $http)
71
    {
72
        parent::__construct();
73
        $this->http = $http;
74
    }
75
76
    /**
77
     * Env var to set.
78
     *
79
     * @return mixed
80
     */
81
    protected function envVar()
82
    {
83
        return 'ACACHA_FORGE_SERVER';
84
    }
85
86
    /**
87
     * Argument key.
88
     *
89
     * @return mixed
90
     */
91
    protected function argKey()
92
    {
93
        return 'server';
94
    }
95
96
    /**
97
     * Question text.
98
     *
99
     * @return mixed
100
     */
101
    protected function questionText()
102
    {
103
        return 'Acacha forge server (forge id)?';
104
    }
105
106
    /**
107
     * Before hook.
108
     */
109
    protected function before()
110
    {
111
        while (! $this->confirm('Do you have a validated server assigned at http:://forge.acacha.com?')) {
0 ignored issues
show
Unused Code introduced by
This while loop is empty and can be removed.

This check looks for while loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
112
        }
113
        $this->servers = $this->fetchServers();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->fetchServers() of type * is incompatible with the declared type array of property $servers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
114
        if (empty($this->servers)) {
115
            $this->error('No valid servers assigned to user!');
116
            die();
117
        }
118
        $this->server_names = collect($this->servers)->pluck('name')->toArray();
119
        $this->server_ids = collect($this->servers)->pluck('forge_id')->toArray();
120
    }
121
122
    /**
123
     * After hook.
124
     */
125
    protected function after()
126
    {
127
        $ip_address = $this->serverIpAddress($this->servers, $this->server);
128
        $server_name = $this->getForgeName($this->servers, $this->server);
129
        $this->call("publish:ip", [
130
            'ip' => $ip_address
131
        ]);
132
        $this->call("publish:server_name", [
133
            'server_name' => $server_name
134
        ]);
135
    }
136
137
    /**
138
     * Default proposed value when asking.
139
     *
140
     */
141
    protected function default()
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
142
    {
143
        return array_search(fp_env('ACACHA_FORGE_SERVER'), $this->server_ids);
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
144
    }
145
146
    /**
147
     * Value.
148
     */
149
    protected function value()
150
    {
151
        $server_name = $this->choice($this->questionText(), $this->server_names, $this->default());
152
        return $this->server = $this->getForgeIdServer($this->servers, $server_name);
153
    }
154
}
155