@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @license MIT |
8 | 8 | */ |
9 | 9 | |
10 | -require_once __DIR__.'/../vendor/autoload.php'; |
|
10 | +require_once __DIR__ . '/../vendor/autoload.php'; |
|
11 | 11 | |
12 | 12 | use chillerlan\Threema\{ |
13 | 13 | Crypto\CryptoSodium, Endpoint\TinyCurlEndpoint, Gateway, GatewayOptions |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | |
19 | 19 | $gatewayOptions = new GatewayOptions; |
20 | 20 | $gatewayOptions->configFilename = '.threema'; // @todo TRAVIS REMINDER! |
21 | -$gatewayOptions->configPath = __DIR__.'/../config'; |
|
22 | -$gatewayOptions->storagePath = __DIR__.'/../storage'; |
|
21 | +$gatewayOptions->configPath = __DIR__ . '/../config'; |
|
22 | +$gatewayOptions->storagePath = __DIR__ . '/../storage'; |
|
23 | 23 | |
24 | 24 | $requestOptions = new RequestOptions; |
25 | -$requestOptions->ca_info = __DIR__.'/../storage/cacert.pem'; // https://curl.haxx.se/ca/cacert.pem |
|
25 | +$requestOptions->ca_info = __DIR__ . '/../storage/cacert.pem'; // https://curl.haxx.se/ca/cacert.pem |
|
26 | 26 | |
27 | 27 | $gateway = new Gateway(new TinyCurlEndpoint($gatewayOptions, new Request($requestOptions))); |
28 | 28 | $cryptoInterface = new CryptoSodium; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | header('Content-type: application/json;charset=utf-8;'); |
41 | -header('Last-Modified: '.date('r')); |
|
41 | +header('Last-Modified: ' . date('r')); |
|
42 | 42 | header('Expires: Tue, 23 May 1989 13:37:23 GMT'); |
43 | 43 | header('Cache-Control: max-age=0, private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); |
44 | 44 | header('Pragma: no-cache'); |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Class EndpointAbstract |
|
4 | - * |
|
5 | - * @filesource EndpointAbstract.php |
|
6 | - * @created 06.04.2016 |
|
7 | - * @package chillerlan\Threema\Endpoint |
|
8 | - * @author Smiley <[email protected]> |
|
9 | - * @copyright 2016 Smiley |
|
10 | - * @license MIT |
|
11 | - */ |
|
3 | + * Class EndpointAbstract |
|
4 | + * |
|
5 | + * @filesource EndpointAbstract.php |
|
6 | + * @created 06.04.2016 |
|
7 | + * @package chillerlan\Threema\Endpoint |
|
8 | + * @author Smiley <[email protected]> |
|
9 | + * @copyright 2016 Smiley |
|
10 | + * @license MIT |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | namespace chillerlan\Threema\Endpoint; |
14 | 14 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @throws \chillerlan\Threema\Endpoint\EndpointException |
49 | 49 | */ |
50 | 50 | private function getResponse(string $endpoint, array $params = [], array $body = []):ResponseInterface{ |
51 | - $endpoint = self::API_BASE.$endpoint; |
|
51 | + $endpoint = self::API_BASE . $endpoint; |
|
52 | 52 | $params = array_merge($params, [ |
53 | 53 | 'from' => getenv('THREEMA_GATEWAY_ID'), |
54 | 54 | 'secret' => getenv('THREEMA_GATEWAY_SECRET') |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | // @codeCoverageIgnoreStart |
67 | 67 | elseif(array_key_exists($response->info->http_code, self::API_ERRORS)){ |
68 | - throw new EndpointException('gateway error: '.self::API_ERRORS[$response->info->http_code]); |
|
68 | + throw new EndpointException('gateway error: ' . self::API_ERRORS[$response->info->http_code]); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | throw new EndpointException('unknown error: "compiles on my machine."'); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @inheritdoc |
84 | 84 | */ |
85 | 85 | public function checkCapabilities(string $threemaID):array{ |
86 | - $response = $this->getResponse('/capabilities/'.$this->checkThreemaID($threemaID))->body->content; |
|
86 | + $response = $this->getResponse('/capabilities/' . $this->checkThreemaID($threemaID))->body->content; |
|
87 | 87 | $response = !empty($response) ? explode(',', $response) : []; |
88 | 88 | |
89 | 89 | sort($response); |
@@ -95,35 +95,35 @@ discard block |
||
95 | 95 | * @inheritdoc |
96 | 96 | */ |
97 | 97 | public function getIdByPhone(string $phoneno):string{ |
98 | - return $this->getResponse('/lookup/phone/'.$this->checkPhoneNo($phoneno))->body->content; |
|
98 | + return $this->getResponse('/lookup/phone/' . $this->checkPhoneNo($phoneno))->body->content; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | 102 | * @inheritdoc |
103 | 103 | */ |
104 | 104 | public function getIdByPhoneHash(string $phonenoHash):string{ |
105 | - return $this->getResponse('/lookup/phone_hash/'.$this->checkHash($phonenoHash))->body->content; |
|
105 | + return $this->getResponse('/lookup/phone_hash/' . $this->checkHash($phonenoHash))->body->content; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * @inheritdoc |
110 | 110 | */ |
111 | 111 | public function getIdByEmail(string $email):string{ |
112 | - return $this->getResponse('/lookup/email/'.$this->checkEmail($email))->body->content; |
|
112 | + return $this->getResponse('/lookup/email/' . $this->checkEmail($email))->body->content; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @inheritdoc |
117 | 117 | */ |
118 | 118 | public function getIdByEmailHash(string $emailHash):string{ |
119 | - return $this->getResponse('/lookup/email_hash/'.$this->checkHash($emailHash))->body->content; |
|
119 | + return $this->getResponse('/lookup/email_hash/' . $this->checkHash($emailHash))->body->content; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @inheritdoc |
124 | 124 | */ |
125 | 125 | public function getPublicKey(string $threemaID):string{ |
126 | - return $this->checkHash($this->getResponse('/pubkeys/'.$this->checkThreemaID($threemaID))->body->content); |
|
126 | + return $this->checkHash($this->getResponse('/pubkeys/' . $this->checkThreemaID($threemaID))->body->content); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | return $this->log2cli($method->invokeArgs($this, $arguments)); |
105 | 105 | } |
106 | 106 | catch(EndpointException $gatewayException){ |
107 | - return $this->log2cli('ERROR: '.$gatewayException->getMessage()); |
|
107 | + return $this->log2cli('ERROR: ' . $gatewayException->getMessage()); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return string |
120 | 120 | */ |
121 | 121 | private function log2cli(string $string):string{ |
122 | - return PHP_EOL.wordwrap($string, 78, PHP_EOL).PHP_EOL; |
|
122 | + return PHP_EOL . wordwrap($string, 78, PHP_EOL) . PHP_EOL; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** @noinspection PhpUnusedPrivateMethodInspection |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | * @param array $tag |
176 | 176 | * @param \stdClass &$out |
177 | 177 | */ |
178 | - private function parseDocTag(array $tag, stdClass &$out){ |
|
178 | + private function parseDocTag(array $tag, stdClass & $out){ |
|
179 | 179 | switch($tag[0]){ |
180 | 180 | case 'param': |
181 | 181 | $tag = (explode(' ', trim($tag[1]), 3)); |
182 | - $name = '<'.trim($tag[1], ' $').'>'; |
|
182 | + $name = '<' . trim($tag[1], ' $') . '>'; |
|
183 | 183 | $out->paramNames[] = $name; |
184 | - $out->paramDoc[] = isset($tag[2]) ? $name.' '.trim($tag[2]) : $name; |
|
184 | + $out->paramDoc[] = isset($tag[2]) ? $name . ' ' . trim($tag[2]) : $name; |
|
185 | 185 | break; |
186 | 186 | case 'return': |
187 | 187 | $tag = explode(' ', trim($tag[1]), 2); |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function help():string{ |
197 | 197 | // return info in case no command was found |
198 | - $help = 'Threema Gateway CLI tool.'.PHP_EOL; |
|
199 | - $help .= 'Crypto: '.$this->cryptoInterface->version().PHP_EOL.PHP_EOL; |
|
198 | + $help = 'Threema Gateway CLI tool.' . PHP_EOL; |
|
199 | + $help .= 'Crypto: ' . $this->cryptoInterface->version() . PHP_EOL . PHP_EOL; |
|
200 | 200 | |
201 | 201 | foreach(self::COMMANDS as $command => $method){ |
202 | 202 | $comment = $this->reflection->getMethod($method)->getDocComment(); |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | $comment = trim(array_shift($params)); |
207 | 207 | $parsed = $this->parseDocBlock($params); |
208 | 208 | |
209 | - $help .= PHP_EOL.'threema.php '.$command.' '.$parsed->paramNames.PHP_EOL; |
|
210 | - $help .= str_repeat('-', strlen($command) + 12).PHP_EOL; |
|
211 | - $help .= PHP_EOL.$comment.PHP_EOL; |
|
212 | - $help .= PHP_EOL.$parsed->paramDoc.PHP_EOL; |
|
213 | - $help .= PHP_EOL.'Returns: '.$parsed->returnDoc.PHP_EOL.PHP_EOL; |
|
209 | + $help .= PHP_EOL . 'threema.php ' . $command . ' ' . $parsed->paramNames . PHP_EOL; |
|
210 | + $help .= str_repeat('-', strlen($command) + 12) . PHP_EOL; |
|
211 | + $help .= PHP_EOL . $comment . PHP_EOL; |
|
212 | + $help .= PHP_EOL . $parsed->paramDoc . PHP_EOL; |
|
213 | + $help .= PHP_EOL . 'Returns: ' . $parsed->returnDoc . PHP_EOL . PHP_EOL; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $help; |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | // @todo: check writable |
227 | 227 | if(is_dir(dirname($path))){ |
228 | 228 | $bytes = file_put_contents($path, $data); |
229 | - return $bytes.' bytes written to: '.$path.PHP_EOL; |
|
229 | + return $bytes . ' bytes written to: ' . $path . PHP_EOL; |
|
230 | 230 | } |
231 | 231 | // or is not writable |
232 | - return $path.' does not exist'; // @codeCoverageIgnore |
|
232 | + return $path . ' does not exist'; // @codeCoverageIgnore |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | public function getKeypair(string $privateKeyFile = null, string $publicKeyFile = null):string{ |
239 | 239 | $keypair = $this->cryptoInterface->getKeypair(); |
240 | 240 | $message = !empty($privateKeyFile) ? $this->writeFile($privateKeyFile, $keypair->privateKey) : ''; |
241 | - $message .= !empty($publicKeyFile) ? $this->writeFile($publicKeyFile, $keypair->publicKey) : ''; |
|
241 | + $message .= !empty($publicKeyFile) ? $this->writeFile($publicKeyFile, $keypair->publicKey) : ''; |
|
242 | 242 | |
243 | - return $message.PHP_EOL.'private:'.$keypair->privateKey.PHP_EOL.'public:'.$keypair->publicKey; |
|
243 | + return $message . PHP_EOL . 'private:' . $keypair->privateKey . PHP_EOL . 'public:' . $keypair->publicKey; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | public function encryptFile(string $privateKey, string $publicKey, string $plaintextFile, string $encryptedFile):string{ |
299 | 299 | $encrypted = $this->cryptoInterface->encrypt(file_get_contents($plaintextFile), $privateKey, $publicKey); |
300 | - return $this->writeFile($encryptedFile, $encrypted->nonce."\n".$encrypted->box); |
|
300 | + return $this->writeFile($encryptedFile, $encrypted->nonce . "\n" . $encrypted->box); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |