1 | <?php |
||
14 | class Host |
||
15 | { |
||
16 | private $config; |
||
17 | private $sshArguments; |
||
18 | |||
19 | 18 | public function __construct(string $hostname) |
|
20 | { |
||
21 | 18 | $parent = null; |
|
22 | 18 | if (Deployer::get()) { |
|
23 | 16 | $parent = Deployer::get()->config; |
|
24 | } |
||
25 | 18 | $this->config = new Configuration($parent); |
|
26 | 18 | $this->set('alias', $hostname); |
|
27 | 18 | $this->set('hostname', preg_replace('/\/.+$/', '', $hostname)); |
|
28 | 18 | $this->set('user', ''); |
|
29 | 18 | $this->set('port', ''); |
|
30 | 18 | $this->set('config_file', ''); |
|
31 | 18 | $this->set('identity_file', ''); |
|
32 | 18 | $this->set('forward_agent', true); |
|
33 | 18 | $this->set('shell', 'bash -s'); |
|
34 | 18 | $this->sshArguments = new Arguments(); |
|
35 | 18 | } |
|
36 | |||
37 | public function getConfig() |
||
38 | { |
||
39 | return $this->config; |
||
40 | } |
||
41 | |||
42 | 18 | public function set(string $name, $value) |
|
43 | { |
||
44 | 18 | $this->config->set($name, $value); |
|
45 | 18 | return $this; |
|
46 | } |
||
47 | |||
48 | 1 | public function add(string $name, array $value) |
|
53 | |||
54 | public function has(string $name): bool |
||
55 | { |
||
56 | return $this->config->has($name); |
||
57 | } |
||
58 | |||
59 | 9 | public function get(string $name, $default = null) |
|
60 | { |
||
61 | 9 | return $this->config->get($name, $default); |
|
62 | } |
||
63 | |||
64 | 10 | public function alias() |
|
68 | |||
69 | 3 | public function hostname() |
|
70 | { |
||
71 | 3 | return $this->config->get('hostname'); |
|
72 | } |
||
73 | |||
74 | 2 | public function user() |
|
78 | |||
79 | 5 | public function port() |
|
80 | { |
||
81 | 5 | return $this->config->get('port'); |
|
82 | } |
||
83 | |||
84 | 3 | public function configFile() |
|
85 | { |
||
86 | 3 | return $this->config->get('config_file'); |
|
87 | } |
||
88 | |||
89 | 4 | public function identityFile() |
|
93 | |||
94 | 3 | public function forwardAgent() |
|
95 | { |
||
96 | 3 | return $this->config->get('forward_agent'); |
|
97 | } |
||
98 | |||
99 | 2 | public function sshMultiplexing() |
|
100 | { |
||
101 | 2 | return $this->config->get('ssh_multiplexing'); |
|
102 | } |
||
103 | |||
104 | public function shell(): string |
||
105 | { |
||
106 | return $this->config->get('shell'); |
||
107 | } |
||
108 | |||
109 | 3 | public function getSshArguments() |
|
114 | |||
115 | // TODO: Migrate to configuration. |
||
116 | 2 | public function sshOptions(array $options): self |
|
117 | { |
||
118 | 2 | $this->sshArguments = $this->sshArguments->withOptions($options); |
|
119 | 2 | return $this; |
|
120 | } |
||
121 | |||
122 | // TODO: Migrate to configuration. |
||
123 | 1 | public function sshFlags(array $flags): self |
|
128 | |||
129 | 3 | private function initOptions() |
|
130 | { |
||
131 | 3 | if ($this->port()) { |
|
132 | 3 | $this->sshArguments = $this->sshArguments->withFlag('-p', $this->port()); |
|
133 | } |
||
134 | |||
135 | 3 | if ($this->configFile()) { |
|
136 | 2 | $this->sshArguments = $this->sshArguments->withFlag('-F', $this->configFile()); |
|
137 | } |
||
138 | |||
139 | 3 | if ($this->identityFile()) { |
|
140 | 2 | $this->sshArguments = $this->sshArguments->withFlag('-i', $this->identityFile()); |
|
147 | |||
148 | public function tag(): string |
||
235 | } |
||
236 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.