@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | $helpfile = __DIR__.'/../storage/ts3help-'.$version.'.json'; |
20 | 20 | |
21 | -if(is_file($helpfile)){ |
|
21 | +if (is_file($helpfile)) { |
|
22 | 22 | unlink($helpfile); |
23 | 23 | } |
24 | 24 | |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | $count = count($help); |
29 | 29 | |
30 | 30 | $temp_commands = []; |
31 | -for($i = $start, $j = 0; $i < $count - $start; $i++, $j++){ |
|
31 | +for ($i = $start, $j = 0; $i < $count - $start; $i++, $j++) { |
|
32 | 32 | |
33 | - if(empty($help[$i])){ |
|
33 | + if (empty($help[$i])) { |
|
34 | 34 | break; |
35 | 35 | } |
36 | 36 | |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | $c->usage = ''; |
47 | 47 | $c->example = ''; |
48 | 48 | |
49 | - if(empty($c->command)){ |
|
49 | + if (empty($c->command)) { |
|
50 | 50 | // add a continued line to the previous command's shortdesc and go on (permreset) |
51 | 51 | $temp_commands[--$j]->shortdesc .= ' '.trim($cmd[1]); |
52 | 52 | |
53 | 53 | continue; |
54 | 54 | } |
55 | - elseif($c->command === 'help'){ |
|
55 | + elseif ($c->command === 'help') { |
|
56 | 56 | continue; |
57 | 57 | } |
58 | 58 | |
@@ -64,32 +64,32 @@ discard block |
||
64 | 64 | $start_description = array_search('Description:', $cmd_help); |
65 | 65 | $start_example = array_search('Example:', $cmd_help); |
66 | 66 | |
67 | - foreach($cmd_help as $key => $value){ |
|
67 | + foreach ($cmd_help as $key => $value) { |
|
68 | 68 | |
69 | - if(empty(trim($value))){ |
|
69 | + if (empty(trim($value))) { |
|
70 | 70 | continue; |
71 | 71 | } |
72 | 72 | |
73 | - if(trim($value) === 'error id=0 msg=ok'){ |
|
73 | + if (trim($value) === 'error id=0 msg=ok') { |
|
74 | 74 | break; |
75 | 75 | } |
76 | 76 | |
77 | - if($key === 0){ |
|
77 | + if ($key === 0) { |
|
78 | 78 | $usage = explode(' ', $value, 2); |
79 | 79 | |
80 | - if($usage[0] === 'Usage:'){ |
|
80 | + if ($usage[0] === 'Usage:') { |
|
81 | 81 | $c->usage = $usage[1]; |
82 | 82 | |
83 | 83 | $params = explode(' ', $c->usage); |
84 | 84 | array_shift($params); |
85 | 85 | |
86 | - $c->params = array_map(function($v){ |
|
86 | + $c->params = array_map(function($v) { |
|
87 | 87 | $p = new \stdClass; |
88 | 88 | |
89 | 89 | $p->name = trim($v, '-[].'); |
90 | 90 | $p->value = null; |
91 | 91 | |
92 | - if(strpos($p->name, '=') > 0){ |
|
92 | + if (strpos($p->name, '=') > 0) { |
|
93 | 93 | $n = explode('=', $p->name); |
94 | 94 | |
95 | 95 | $p->name = $n[0]; |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | } |
104 | - else if($start_permissions > 1 && $key > $start_permissions && $key < $start_description){ |
|
104 | + else if ($start_permissions > 1 && $key > $start_permissions && $key < $start_description) { |
|
105 | 105 | $c->permissions .= ' '.trim($value); |
106 | 106 | } |
107 | - else if($start_description > $start_permissions && $key > $start_description && $key < $start_example){ |
|
107 | + else if ($start_description > $start_permissions && $key > $start_description && $key < $start_example) { |
|
108 | 108 | $c->description .= ' '.trim($value); |
109 | 109 | } |
110 | - else if($start_example > $start_description && $key > $start_example){ |
|
110 | + else if ($start_example > $start_description && $key > $start_example) { |
|
111 | 111 | $c->example .= trim($value).PHP_EOL; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | 115 | } |
116 | 116 | |
117 | -foreach($temp_commands as $cm){ |
|
117 | +foreach ($temp_commands as $cm) { |
|
118 | 118 | $cm->description = trim($cm->description); |
119 | 119 | $cm->permissions = !empty($cm->permissions) |
120 | 120 | ? explode(' ', trim($cm->permissions)) |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $example->request = $ex[0]; |
128 | 128 | $example->response = null; |
129 | 129 | |
130 | - if(isset($ex[1]) && !empty($ex[1])){ |
|
130 | + if (isset($ex[1]) && !empty($ex[1])) { |
|
131 | 131 | $example->response = $ex[1]; |
132 | 132 | } |
133 | 133 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $p = []; |
137 | 137 | |
138 | - foreach($cm->params as $param){ |
|
138 | + foreach ($cm->params as $param) { |
|
139 | 139 | $p[$param->name] = $param; |
140 | 140 | } |
141 | 141 |
@@ -51,8 +51,7 @@ discard block |
||
51 | 51 | $temp_commands[--$j]->shortdesc .= ' '.trim($cmd[1]); |
52 | 52 | |
53 | 53 | continue; |
54 | - } |
|
55 | - elseif($c->command === 'help'){ |
|
54 | + } elseif($c->command === 'help'){ |
|
56 | 55 | continue; |
57 | 56 | } |
58 | 57 | |
@@ -100,14 +99,11 @@ discard block |
||
100 | 99 | }, $params); |
101 | 100 | } |
102 | 101 | |
103 | - } |
|
104 | - else if($start_permissions > 1 && $key > $start_permissions && $key < $start_description){ |
|
102 | + } else if($start_permissions > 1 && $key > $start_permissions && $key < $start_description){ |
|
105 | 103 | $c->permissions .= ' '.trim($value); |
106 | - } |
|
107 | - else if($start_description > $start_permissions && $key > $start_description && $key < $start_example){ |
|
104 | + } else if($start_description > $start_permissions && $key > $start_description && $key < $start_example){ |
|
108 | 105 | $c->description .= ' '.trim($value); |
109 | - } |
|
110 | - else if($start_example > $start_description && $key > $start_example){ |
|
106 | + } else if($start_example > $start_description && $key > $start_example){ |
|
111 | 107 | $c->example .= trim($value).PHP_EOL; |
112 | 108 | } |
113 | 109 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | interface TS3QueryInterface{'.PHP_EOL; |
45 | 45 | |
46 | -foreach($methodlist as $method){ |
|
46 | +foreach ($methodlist as $method) { |
|
47 | 47 | |
48 | 48 | $interface .= ' |
49 | 49 | /** |
@@ -53,19 +53,19 @@ discard block |
||
53 | 53 | * |
54 | 54 | * Description:'; |
55 | 55 | |
56 | - foreach(explode(PHP_EOL, wordwrap($method->description, 100, PHP_EOL)) as $line){ |
|
56 | + foreach (explode(PHP_EOL, wordwrap($method->description, 100, PHP_EOL)) as $line) { |
|
57 | 57 | $interface .= ' |
58 | 58 | * '.$line; |
59 | 59 | } |
60 | 60 | |
61 | - if(!empty($method->permissions)){ |
|
61 | + if (!empty($method->permissions)) { |
|
62 | 62 | $interface .= ' |
63 | 63 | * |
64 | 64 | * Permissions:'; |
65 | 65 | |
66 | 66 | sort($method->permissions); |
67 | 67 | |
68 | - foreach($method->permissions as $perm){ |
|
68 | + foreach ($method->permissions as $perm) { |
|
69 | 69 | $interface .= ' |
70 | 70 | * - '.$perm; |
71 | 71 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * - Request: |
82 | 82 | * '.$method->example->request; |
83 | 83 | |
84 | - if(!empty($method->example->response)){ |
|
84 | + if (!empty($method->example->response)) { |
|
85 | 85 | $interface .= ' |
86 | 86 | * - Response: |
87 | 87 | * '.$method->example->response; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | *'; |
93 | 93 | |
94 | 94 | $args = ''; |
95 | - if(!empty($method->params)){ |
|
95 | + if (!empty($method->params)) { |
|
96 | 96 | |
97 | 97 | $interface .= ' |
98 | 98 | * @param array $params'; |
99 | 99 | |
100 | - foreach($method->params as $p){ |
|
100 | + foreach ($method->params as $p) { |
|
101 | 101 | $interface .= ' |
102 | - * - '.$p->name.(!is_null($p->value) ? ' ('.$p->value.')' : ' [optional]'); |
|
102 | + * - '.$p->name.(!is_null($p->value) ? ' ('.$p->value.')' : ' [optional]'); |
|
103 | 103 | |
104 | 104 | $args .= '\''.$p->name.'\''.(!is_null($p->value) ? ' => \''.$p->value.'\'' : '').', '; |
105 | 105 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * |
17 | 17 | */ |
18 | -class TS3Client{ |
|
18 | +class TS3Client { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \chillerlan\Teamspeak\TS3Config |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param \chillerlan\Teamspeak\TS3Config $config |
34 | 34 | */ |
35 | - public function __construct(TS3Config $config){ |
|
35 | + public function __construct(TS3Config $config) { |
|
36 | 36 | $this->config = $config; |
37 | 37 | |
38 | - if(!is_int($this->config->vserver)){ |
|
38 | + if (!is_int($this->config->vserver)) { |
|
39 | 39 | $this->config->vserver = 1; |
40 | 40 | } |
41 | 41 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * |
45 | 45 | */ |
46 | - public function __destruct(){ |
|
46 | + public function __destruct() { |
|
47 | 47 | return $this->disconnect(); |
48 | 48 | } |
49 | 49 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @throws \chillerlan\Teamspeak\TS3ClientException |
53 | 53 | */ |
54 | 54 | public function connect():array { |
55 | - $this->socket = @fsockopen($this->config->host, $this->config->port, $errno, $errstr,3); |
|
55 | + $this->socket = @fsockopen($this->config->host, $this->config->port, $errno, $errstr, 3); |
|
56 | 56 | |
57 | - if(!$this->socket){ |
|
57 | + if (!$this->socket) { |
|
58 | 58 | throw new TS3ClientException('could not connect: #'.$errno.' '.$errstr); |
59 | 59 | } |
60 | 60 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function disconnect():array { |
73 | 73 | |
74 | - if($this->socket){ |
|
74 | + if ($this->socket) { |
|
75 | 75 | $r = [ |
76 | 76 | $this->send('logout'), |
77 | 77 | $this->send('quit'), |
@@ -96,17 +96,17 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function send(string $command):TS3Response { |
98 | 98 | |
99 | - if(!$this->socket){ |
|
99 | + if (!$this->socket) { |
|
100 | 100 | throw new TS3ClientException('not connected'); |
101 | 101 | } |
102 | 102 | |
103 | 103 | $command = trim($command); |
104 | 104 | |
105 | - if(empty($command)){ |
|
105 | + if (empty($command)) { |
|
106 | 106 | throw new TS3ClientException('empty command'); |
107 | 107 | } |
108 | 108 | |
109 | - if(fwrite($this->socket, $command.PHP_EOL) !== false){ |
|
109 | + if (fwrite($this->socket, $command.PHP_EOL) !== false) { |
|
110 | 110 | return new TS3Response($command, stream_get_contents($this->socket)); |
111 | 111 | } |
112 | 112 |
@@ -19,7 +19,7 @@ |
||
19 | 19 | /** |
20 | 20 | * |
21 | 21 | */ |
22 | -interface TS3QueryInterface{ |
|
22 | +interface TS3QueryInterface { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Banadd |
@@ -14,6 +14,6 @@ |
||
14 | 14 | |
15 | 15 | /** |
16 | 16 | */ |
17 | -class TS3ClientException extends \Exception{ |
|
17 | +class TS3ClientException extends \Exception { |
|
18 | 18 | |
19 | 19 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @property array $data |
20 | 20 | * @property \stdClass $error |
21 | 21 | */ |
22 | -class TS3Response{ |
|
22 | +class TS3Response { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @var string |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param string $command |
53 | 53 | * @param string $raw |
54 | 54 | */ |
55 | - public function __construct(string $command, string $raw){ |
|
55 | + public function __construct(string $command, string $raw) { |
|
56 | 56 | $this->commandline = $command; |
57 | 57 | $this->raw = $raw; |
58 | 58 | |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return mixed |
66 | 66 | */ |
67 | - public function __get(string $property){ |
|
67 | + public function __get(string $property) { |
|
68 | 68 | |
69 | - if(property_exists($this, $property)){ |
|
69 | + if (property_exists($this, $property)) { |
|
70 | 70 | return $this->{$property}; |
71 | 71 | } |
72 | 72 | |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * |
78 | 78 | */ |
79 | - protected function parse_response(){ |
|
79 | + protected function parse_response() { |
|
80 | 80 | |
81 | - $this->commandlist = array_map(function($c){ |
|
81 | + $this->commandlist = array_map(function($c) { |
|
82 | 82 | return trim($c, "\r\n\t- "); |
83 | 83 | }, explode(' ', trim($this->commandline))); |
84 | 84 | |
85 | - $this->data = array_map(function($d){ |
|
85 | + $this->data = array_map(function($d) { |
|
86 | 86 | return trim($d); |
87 | 87 | }, explode("\n", trim($this->raw))); |
88 | 88 | |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | $this->error->id = null; |
92 | 92 | $this->error->msg = null; |
93 | 93 | |
94 | - if(preg_match( |
|
94 | + if (preg_match( |
|
95 | 95 | '/^(:?error id=)(?P<id>[\d]+)(:? msg=)(?P<msg>.*)$/isU', |
96 | 96 | array_pop($this->data), |
97 | 97 | $match |
98 | 98 | ) > 0 |
99 | - ){ |
|
99 | + ) { |
|
100 | 100 | $this->error->id = (int)$match['id']; |
101 | 101 | $this->error->msg = $match['msg']; |
102 | 102 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $r = new \stdClass; |
120 | 120 | |
121 | - foreach($str as $pair){ |
|
121 | + foreach ($str as $pair) { |
|
122 | 122 | $kv = explode('=', $pair); |
123 | 123 | |
124 | 124 | $r->{$kv[0]} = isset($kv[1]) && !empty($kv[1]) |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | public function parse_list(string $str = null) { |
142 | 142 | $str = !empty($str) ? $str : $this->data[0]; |
143 | 143 | |
144 | - if(strpos($str, '|')){ |
|
144 | + if (strpos($str, '|')) { |
|
145 | 145 | $str = explode('|', $str); |
146 | 146 | |
147 | 147 | $arr = []; |
148 | 148 | |
149 | - foreach($str as $line){ |
|
149 | + foreach ($str as $line) { |
|
150 | 150 | $arr[] = $this->parse_kv($line); |
151 | 151 | } |
152 | 152 |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @method void servertemppasswordadd($params = ['pw' => 'password', 'desc' => 'description']) |
135 | 135 | * @method void servertemppassworddel($params = ['pw' => 'password']) |
136 | 136 | */ |
137 | -class TS3QueryAPI extends TS3Client{ |
|
137 | +class TS3QueryAPI extends TS3Client { |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @var \stdClass |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @param \chillerlan\Teamspeak\TS3Config $config |
148 | 148 | */ |
149 | - public function __construct(TS3Config $config){ |
|
149 | + public function __construct(TS3Config $config) { |
|
150 | 150 | parent::__construct($config); |
151 | 151 | $this->connect(); |
152 | 152 | $this->map_api(); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | protected function map_api():TS3QueryAPI { |
160 | 160 | $file = $this->config->storagedir.$this->config->filename.'-'.$this->config->apiversion.'.json'; |
161 | 161 | |
162 | - if(!is_file($file)){ |
|
162 | + if (!is_file($file)) { |
|
163 | 163 | throw new TS3ClientException('please create a helpfile first'); |
164 | 164 | } |
165 | 165 | |
@@ -177,23 +177,23 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function __call(string $method, array $arguments):TS3Response { |
179 | 179 | |
180 | - if(isset($this->methods->{$method})){ |
|
180 | + if (isset($this->methods->{$method})) { |
|
181 | 181 | $m = $this->methods->{$method}; |
182 | 182 | $args = []; |
183 | 183 | |
184 | - if(!empty($m->params) && is_array($arguments[0]) && !empty($arguments[0])){ |
|
184 | + if (!empty($m->params) && is_array($arguments[0]) && !empty($arguments[0])) { |
|
185 | 185 | |
186 | - foreach($arguments[0] as $k => $param){ |
|
186 | + foreach ($arguments[0] as $k => $param) { |
|
187 | 187 | |
188 | - if(is_int($k)){ |
|
188 | + if (is_int($k)) { |
|
189 | 189 | |
190 | - if(isset($m->params->{$param}) && !is_null($m->params->{$param}->value)){ |
|
190 | + if (isset($m->params->{$param}) && !is_null($m->params->{$param}->value)) { |
|
191 | 191 | throw new TS3ClientException('parameter value '.$param.'='.$m->params->{$param}->value.' not set'); |
192 | 192 | } |
193 | 193 | |
194 | 194 | $args[] = '-'.$param; |
195 | 195 | } |
196 | - else{ |
|
196 | + else { |
|
197 | 197 | $args[] = '-'.$k.'='.$param; |
198 | 198 | } |
199 | 199 |
@@ -192,8 +192,7 @@ |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | $args[] = '-'.$param; |
195 | - } |
|
196 | - else{ |
|
195 | + } else{ |
|
197 | 196 | $args[] = '-'.$k.'='.$param; |
198 | 197 | } |
199 | 198 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | /** |
15 | 15 | * Class TS3Config |
16 | 16 | */ |
17 | -class TS3Config{ |
|
17 | +class TS3Config { |
|
18 | 18 | |
19 | 19 | public $host = 'localhost'; |
20 | 20 | public $port = 10011; |