GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Pull Request — master (#1904)
by Anton
01:48
created

Host::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Host;
9
10
use Deployer\Configuration\Configuration;
11
use Deployer\Component\Ssh\Arguments;
12
use Deployer\Deployer;
13
14
class Host
15
{
16
    private $config;
17
    private $sshArguments;
18
19
    public function __construct(string $hostname)
20
    {
21
        $parent = null;
22
        if (Deployer::get()) {
23
            $parent = Deployer::get()->config;
24
        }
25
        $this->config = new Configuration($parent);
26
        $this->set('alias', $hostname);
27
        $this->set('hostname', preg_replace('/\/.+$/', '', $hostname));
28
        $this->set('user', '');
29
        $this->set('port', '');
30
        $this->set('config_file', '');
31
        $this->set('identity_file', '');
32
        $this->set('forward_agent', true);
33 34
        $this->set('shell', 'bash -s');
34
        $this->sshArguments = new Arguments();
35 34
    }
36 34
37 34
    public function getConfig()
38 34
    {
39 34
        return $this->config;
40
    }
41 3
42
    public function set(string $name, $value)
43 3
    {
44 3
        $this->config->set($name, $value);
45
        return $this;
46
    }
47 3
48 2
    public function add(string $name, array $value)
49
    {
50
        $this->config->add($name, $value);
51 3
        return $this;
52 2
    }
53
54
    public function has(string $name): bool
55 3
    {
56 3
        return $this->config->has($name);
57
    }
58 3
59
    public function get(string $name, $default = null)
60
    {
61
        return $this->config->get($name, $default);
62
    }
63
64
    public function alias()
65 6
    {
66
        return $this->config->get('alias');
67 6
    }
68 6
69
    public function hostname()
70
    {
71
        return $this->config->get('hostname');
72
    }
73
74 28
    public function user()
75
    {
76 28
        return $this->config->get('user');
77
    }
78
79
    public function port()
80
    {
81
        return $this->config->get('port');
82
    }
83
84
    public function configFile()
85
    {
86
        return $this->config->get('config_file');
87 4
    }
88
89 4
    public function identityFile()
90 4
    {
91
        return $this->config->get('identity_file');
92
    }
93
94
    public function forwardAgent()
95
    {
96 34
        return $this->config->get('forward_agent');
97
    }
98 34
99 34
    public function sshMultiplexing()
100
    {
101
        return $this->config->get('ssh_multiplexing');
102
    }
103
104 2
    public function shell(): string
105
    {
106 2
        return $this->config->get('shell');
107
    }
108
109 4
    public function getSshArguments()
110
    {
111 4
        $this->initOptions();
112 4
        return $this->sshArguments;
113
    }
114
115
    // TODO: Migrate to configuration.
116
    public function sshOptions(array $options): self
117
    {
118 4
        $this->sshArguments = $this->sshArguments->withOptions($options);
119
        return $this;
120 4
    }
121
122
    // TODO: Migrate to configuration.
123 4
    public function sshFlags(array $flags): self
124
    {
125 4
        $this->sshArguments = $this->sshArguments->withFlags($flags);
126 4
        return $this;
127
    }
128
129
    private function initOptions()
130
    {
131
        if ($this->port()) {
132 2
            $this->sshArguments = $this->sshArguments->withFlag('-p', $this->port());
133
        }
134 2
135
        if ($this->configFile()) {
136
            $this->sshArguments = $this->sshArguments->withFlag('-F', $this->configFile());
137 3
        }
138
139 3
        if ($this->identityFile()) {
140 3
            $this->sshArguments = $this->sshArguments->withFlag('-i', $this->identityFile());
141
        }
142
143
        if ($this->forwardAgent()) {
144
            $this->sshArguments = $this->sshArguments->withFlag('-A');
145
        }
146 3
    }
147
148 3
    public function tag(): string
149
    {
150
        if ($this->config->has('tag')) {
151 4
            return $this->config->get('tag');
152
        }
153 4
154 4
        if (defined('NO_ANSI')) {
155
            return $this->alias();
156
        }
157
158
        if (getenv('COLORTERM') === 'truecolor') {
159
            $hsv = function ($h, $s, $v) {
160 2
                $r = $g = $b = $i = $f = $p = $q = $t = 0;
0 ignored issues
show
Unused Code introduced by
$t is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$q is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$p is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$f is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$i is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
161
                $i = floor($h * 6);
162 2
                $f = $h * 6 - $i;
163
                $p = $v * (1 - $s);
164
                $q = $v * (1 - $f * $s);
165 3
                $t = $v * (1 - (1 - $f) * $s);
166
                switch ($i % 6) {
167 3
                    case 0:
168 3
                        $r = $v;
169
                        $g = $t;
170
                        $b = $p;
171
                        break;
172
                    case 1:
173
                        $r = $q;
174 2
                        $g = $v;
175
                        $b = $p;
176 2
                        break;
177
                    case 2:
178
                        $r = $p;
179 3
                        $g = $v;
180
                        $b = $t;
181 3
                        break;
182 3
                    case 3:
183
                        $r = $p;
184
                        $g = $q;
185 3
                        $b = $v;
186
                        break;
187 3
                    case 4:
188 3
                        $r = $t;
189
                        $g = $p;
190
                        $b = $v;
191 3
                        break;
192
                    case 5:
193 3
                        $r = $v;
194 3
                        $g = $p;
195
                        $b = $q;
196
                        break;
197 2
                }
198
                $r = round($r * 255);
199 2
                $g = round($g * 255);
200 2
                $b = round($b * 255);
201
                return "\x1b[38;2;{$r};{$g};{$b}m";
202
            };
203 1
204
            $total = 100;
205 1
            $colors = [];
206 1
            for ($i = 0; $i < $total; $i++) {
207
                $colors[] = $hsv($i / $total, 1, .9);
208
            }
209
210
            $alias = $this->alias();
211
            $tag = $colors[abs(crc32($alias)) % count($colors)];
212
213
            return "{$tag}{$alias}\x1b[0m";
214
        }
215
216
217
        $colors = [
218
            'fg=cyan;options=bold',
219
            'fg=green;options=bold',
220
            'fg=yellow;options=bold',
221
            'fg=cyan',
222
            'fg=blue',
223
            'fg=yellow',
224
            'fg=magenta',
225
            'fg=blue;options=bold',
226 5
            'fg=green',
227
            'fg=magenta;options=bold',
228 5
            'fg=red;options=bold',
229 5
        ];
230
        $alias = $this->alias();
231
        $tag = $colors[abs(crc32($alias)) % count($colors)];
232 5
233
        return "<{$tag}>{$alias}</>";
234 5
    }
235
}
236