1 | <?php |
||
16 | class Arguments |
||
17 | { |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $flags = []; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $options = []; |
||
27 | |||
28 | 9 | public function getCliArguments() |
|
29 | { |
||
30 | 9 | $boolFlags = array_keys(array_filter($this->flags, 'is_null')); |
|
31 | |||
32 | 9 | $valueFlags = array_filter($this->flags); |
|
33 | 9 | $valueFlags = array_map(function ($key, $value) { |
|
34 | 4 | return "$key $value"; |
|
35 | 9 | }, array_keys($valueFlags), $valueFlags); |
|
36 | |||
37 | 9 | $options = array_map(function ($key, $value) { |
|
38 | 7 | return "-o $key=$value"; |
|
39 | 9 | }, array_keys($this->options), $this->options); |
|
40 | |||
41 | 9 | $args = sprintf('%s %s %s', implode(' ', $boolFlags), implode(' ', $valueFlags), implode(' ', $options)); |
|
42 | |||
43 | 9 | return trim(preg_replace('!\s+!', ' ', $args)); |
|
44 | } |
||
45 | |||
46 | 3 | public function getOption(string $option) |
|
50 | |||
51 | 1 | public function getFlag(string $flag) |
|
59 | |||
60 | 8 | public function withFlags(array $flags) |
|
67 | |||
68 | 10 | public function withOptions(array $options) |
|
75 | |||
76 | 4 | public function withFlag(string $flag, string $value = null) |
|
83 | |||
84 | 4 | public function withOption(string $option, string $value) |
|
91 | |||
92 | 4 | public function withDefaults(Arguments $defaultOptions) |
|
100 | |||
101 | 2 | public function withMultiplexing(Host $host) |
|
113 | |||
114 | /** |
||
115 | * Return SSH multiplexing control path |
||
116 | * |
||
117 | * When ControlPath is longer than 104 chars we can get: |
||
118 | * |
||
119 | * SSH Error: unix_listener: too long for Unix domain socket |
||
120 | * |
||
121 | * So try to get as descriptive path as possible. |
||
122 | * %C is for creating hash out of connection attributes. |
||
123 | * |
||
124 | * @param Host $host |
||
125 | * @return string ControlPath |
||
126 | * @throws Exception |
||
127 | */ |
||
128 | 2 | private function generateControlPath(Host $host) |
|
158 | |||
159 | private function buildFlagsFromArray($flags) |
||
179 | |||
180 | public function __toString() |
||
184 | } |
||
185 |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.