@@ -51,7 +51,7 @@ |
||
51 | 51 | $helper = new E2EHelper($privateKey, $connector); |
52 | 52 | $result = $helper->sendImageMessage($threemaId, $path); |
53 | 53 | |
54 | - if($result->isSuccess()) { |
|
54 | + if ($result->isSuccess()) { |
|
55 | 55 | Common::l('Message ID: '.$result->getMessageId()); |
56 | 56 | } |
57 | 57 | else { |
@@ -41,8 +41,7 @@ |
||
41 | 41 | $storeHandle = fopen($this->file, 'r'); |
42 | 42 | if(false === $storeHandle) { |
43 | 43 | throw new Exception('could not open file '.$this->file); |
44 | - } |
|
45 | - else { |
|
44 | + } else { |
|
46 | 45 | $threemaId = strtoupper($threemaId); |
47 | 46 | $publicKey = null; |
48 | 47 | while (!feof($storeHandle)) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | Common::required($to, $from, $secret); |
37 | 37 | |
38 | 38 | $message = $this->readStdIn(); |
39 | - if(strlen($message) === 0) { |
|
39 | + if (strlen($message) === 0) { |
|
40 | 40 | throw new \InvalidArgumentException('please define a message'); |
41 | 41 | } |
42 | 42 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $receiver = new Receiver($to, Receiver::TYPE_ID); |
50 | 50 | |
51 | 51 | $result = $connector->sendSimple($receiver, $message); |
52 | - if($result->isSuccess()) { |
|
52 | + if ($result->isSuccess()) { |
|
53 | 53 | Common::l('Message ID: '.$result->getMessageId()); |
54 | 54 | } |
55 | 55 | else { |
@@ -41,8 +41,7 @@ |
||
41 | 41 | $storeHandle = fopen($this->file, 'r'); |
42 | 42 | if(false === $storeHandle) { |
43 | 43 | throw new Exception('could not open file '.$this->file); |
44 | - } |
|
45 | - else { |
|
44 | + } else { |
|
46 | 45 | $threemaId = strtoupper($threemaId); |
47 | 46 | $publicKey = null; |
48 | 47 | while (!feof($storeHandle)) { |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function l($string = '', $indent = 0) { |
21 | 21 | $pad = str_repeat(' ', $indent); |
22 | - echo $pad . wordwrap($string, 100, "\n" . $pad) . "\n"; |
|
22 | + echo $pad.wordwrap($string, 100, "\n".$pad)."\n"; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param string $string string to output |
29 | 29 | */ |
30 | 30 | public static function ln($string = '') { |
31 | - echo $string . "\n"; |
|
31 | + echo $string."\n"; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public static function required() { |
52 | 52 | $argCount = func_num_args(); |
53 | - for($n = 0; $n < $argCount; $n++) { |
|
53 | + for ($n = 0; $n < $argCount; $n++) { |
|
54 | 54 | $o = func_get_arg($n); |
55 | - if(null === $o || (is_scalar($o) && strlen($o) == 0)) { |
|
55 | + if (null === $o || (is_scalar($o) && strlen($o) == 0)) { |
|
56 | 56 | throw new Exception('invalid data'); |
57 | 57 | } |
58 | 58 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @return null|string |
66 | 66 | */ |
67 | 67 | public static function convertPublicKey($key) { |
68 | - if(null !== $key) { |
|
68 | + if (null !== $key) { |
|
69 | 69 | return Constants::PUBLIC_KEY_PREFIX.$key; |
70 | 70 | } |
71 | 71 | return null; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return null|string |
79 | 79 | */ |
80 | 80 | public static function getPublicKey($stringWithPrefix = null) { |
81 | - if(null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PUBLIC_KEY_PREFIX)) == Constants::PUBLIC_KEY_PREFIX) { |
|
81 | + if (null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PUBLIC_KEY_PREFIX)) == Constants::PUBLIC_KEY_PREFIX) { |
|
82 | 82 | return substr($stringWithPrefix, strlen(Constants::PUBLIC_KEY_PREFIX)); |
83 | 83 | } |
84 | 84 | return null; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return null|string |
92 | 92 | */ |
93 | 93 | public static function convertPrivateKey($key) { |
94 | - if(null !== $key) { |
|
94 | + if (null !== $key) { |
|
95 | 95 | return Constants::PRIVATE_KEY_PREFIX.$key; |
96 | 96 | } |
97 | 97 | return null; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return null|string |
105 | 105 | */ |
106 | 106 | public static function getPrivateKey($stringWithPrefix = null) { |
107 | - if(null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PRIVATE_KEY_PREFIX)) == Constants::PRIVATE_KEY_PREFIX) { |
|
107 | + if (null !== $stringWithPrefix && substr($stringWithPrefix, 0, strlen(Constants::PRIVATE_KEY_PREFIX)) == Constants::PRIVATE_KEY_PREFIX) { |
|
108 | 108 | return substr($stringWithPrefix, strlen(Constants::PRIVATE_KEY_PREFIX)); |
109 | 109 | } |
110 | 110 | return null; |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | private function register($argumentKey, Base $command) { |
89 | - if(is_scalar($argumentKey)) { |
|
89 | + if (is_scalar($argumentKey)) { |
|
90 | 90 | $argumentKey = array($argumentKey); |
91 | 91 | } |
92 | 92 | |
93 | 93 | //check for existing commands with the same arguments |
94 | - foreach($this->commands as $commandValues) { |
|
94 | + foreach ($this->commands as $commandValues) { |
|
95 | 95 | $ex = $commandValues[0]; |
96 | - if(null !== $ex && is_array($ex)) { |
|
97 | - if(count($ex) == count($argumentKey) |
|
96 | + if (null !== $ex && is_array($ex)) { |
|
97 | + if (count($ex) == count($argumentKey) |
|
98 | 98 | && count(array_diff($ex, $argumentKey)) == 0) { |
99 | 99 | throw new Exception('arguments '.implode($argumentKey).' already used'); |
100 | 100 | } |
@@ -113,17 +113,17 @@ discard block |
||
113 | 113 | $argumentLength = 0; |
114 | 114 | |
115 | 115 | //find the correct command by arguments and arguments count |
116 | - foreach($this->commands as $data) { |
|
117 | - if(is_scalar($data)) { |
|
116 | + foreach ($this->commands as $data) { |
|
117 | + if (is_scalar($data)) { |
|
118 | 118 | continue; |
119 | 119 | } |
120 | 120 | |
121 | 121 | list($keys, $command) = $data; |
122 | - if(array_slice($this->arguments, 0, count($keys)) == $keys) { |
|
122 | + if (array_slice($this->arguments, 0, count($keys)) == $keys) { |
|
123 | 123 | $argCount = count($this->arguments)-count($keys); |
124 | 124 | |
125 | 125 | /** @noinspection PhpUndefinedMethodInspection */ |
126 | - if($argCount >= $command->getRequiredArgumentCount() |
|
126 | + if ($argCount >= $command->getRequiredArgumentCount() |
|
127 | 127 | && $argCount <= $command->getAllArgumentsCount()) { |
128 | 128 | $found = $command; |
129 | 129 | $argumentLength = count($keys); |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | - if($argumentLength > 0) { |
|
135 | + if ($argumentLength > 0) { |
|
136 | 136 | array_splice($this->arguments, 0, $argumentLength); |
137 | 137 | } |
138 | 138 | |
139 | - if(null === $found) { |
|
139 | + if (null === $found) { |
|
140 | 140 | $this->help(); |
141 | 141 | } |
142 | 142 | else { |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | try { |
146 | 146 | $found->run($this->arguments); |
147 | 147 | } |
148 | - catch(Exception $x) { |
|
148 | + catch (Exception $x) { |
|
149 | 149 | Common::l(); |
150 | 150 | Common::e('ERROR: '.$x->getMessage()); |
151 | 151 | Common::e(get_class($x)); |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | Common::l('CryptTool: '.$defaultCryptTool->getName().' '.$defaultCryptTool->getDescription()); |
164 | 164 | Common::l(str_repeat('.', 40)); |
165 | 165 | Common::l(); |
166 | - foreach($this->commands as $data) { |
|
167 | - if(is_scalar($data)) { |
|
166 | + foreach ($this->commands as $data) { |
|
167 | + if (is_scalar($data)) { |
|
168 | 168 | Common::l($data); |
169 | 169 | Common::l(str_repeat('-', strlen($data))); |
170 | 170 | Common::l(); |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | public function writeHelp(\Closure $writer) { |
184 | - if(null !== $writer) { |
|
184 | + if (null !== $writer) { |
|
185 | 185 | |
186 | - foreach($this->commands as $data) { |
|
187 | - if(is_scalar($data)) { |
|
186 | + foreach ($this->commands as $data) { |
|
187 | + if (is_scalar($data)) { |
|
188 | 188 | $writer->__invoke($data, null, null, false); |
189 | 189 | } |
190 | 190 | else { |
@@ -138,14 +138,12 @@ discard block |
||
138 | 138 | |
139 | 139 | if(null === $found) { |
140 | 140 | $this->help(); |
141 | - } |
|
142 | - else { |
|
141 | + } else { |
|
143 | 142 | |
144 | 143 | |
145 | 144 | try { |
146 | 145 | $found->run($this->arguments); |
147 | - } |
|
148 | - catch(Exception $x) { |
|
146 | + } catch(Exception $x) { |
|
149 | 147 | Common::l(); |
150 | 148 | Common::e('ERROR: '.$x->getMessage()); |
151 | 149 | Common::e(get_class($x)); |
@@ -168,8 +166,7 @@ discard block |
||
168 | 166 | Common::l($data); |
169 | 167 | Common::l(str_repeat('-', strlen($data))); |
170 | 168 | Common::l(); |
171 | - } |
|
172 | - else { |
|
169 | + } else { |
|
173 | 170 | list($key, $command) = $data; |
174 | 171 | Common::ln($this->scriptName.' '."\033[1;33m".implode(' ', $key)."\033[0m".' '.$command->help()); |
175 | 172 | Common::l(); |
@@ -186,8 +183,7 @@ discard block |
||
186 | 183 | foreach($this->commands as $data) { |
187 | 184 | if(is_scalar($data)) { |
188 | 185 | $writer->__invoke($data, null, null, false); |
189 | - } |
|
190 | - else { |
|
186 | + } else { |
|
191 | 187 | list($key, $command) = $data; |
192 | 188 | $writer->__invoke($command->subject(false), $this->scriptName.' '.implode(' ', $key).' '.$command->help(false), $command->description(), true); |
193 | 189 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @return mixed|null return the key value or the default value |
29 | 29 | */ |
30 | 30 | public function getValue($key, $defaultValue = null) { |
31 | - if(false === array_key_exists($key, $this->data)) { |
|
31 | + if (false === array_key_exists($key, $this->data)) { |
|
32 | 32 | return $defaultValue; |
33 | 33 | } |
34 | 34 | |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static final function byJsonString($string, array $requiredKeys = null) { |
45 | 45 | $v = json_decode($string, true); |
46 | - if(null === $v || false === $v) { |
|
46 | + if (null === $v || false === $v) { |
|
47 | 47 | throw new Exception('invalid json string'); |
48 | 48 | } |
49 | 49 | |
50 | 50 | //validate first |
51 | - if(null !== $requiredKeys) { |
|
51 | + if (null !== $requiredKeys) { |
|
52 | 52 | //validate array first |
53 | - foreach($requiredKeys as $requiredKey) { |
|
54 | - if(false === array($v)) { |
|
53 | + foreach ($requiredKeys as $requiredKey) { |
|
54 | + if (false === array($v)) { |
|
55 | 55 | throw new Exception('required key '.$requiredKey.' failed'); |
56 | 56 | } |
57 | 57 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param string $value |
39 | 39 | * @return $this |
40 | 40 | */ |
41 | - public function setValue($key, $value){ |
|
41 | + public function setValue($key, $value) { |
|
42 | 42 | $this->values[$key] = $value; |
43 | 43 | return $this; |
44 | 44 | } |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | * @return $this |
51 | 51 | */ |
52 | 52 | public function addPath($path) { |
53 | - while(substr($this->path, strlen($this->path)-1) == '/') { |
|
53 | + while (substr($this->path, strlen($this->path)-1) == '/') { |
|
54 | 54 | $this->path = substr($this->path, 0, strlen($this->path)-1); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $realPath = ''; |
58 | - foreach(explode('/', $path) as $c => $pathPiece) { |
|
59 | - if($c > 0) { |
|
58 | + foreach (explode('/', $path) as $c => $pathPiece) { |
|
59 | + if ($c > 0) { |
|
60 | 60 | $realPath .= '/'; |
61 | 61 | } |
62 | 62 | $realPath .= urlencode($pathPiece); |
63 | 63 | } |
64 | - while(substr($path, 0, 1) == '/') { |
|
64 | + while (substr($path, 0, 1) == '/') { |
|
65 | 65 | $path = substr($path, 1); |
66 | 66 | } |
67 | 67 | |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function getPath() { |
76 | 76 | $p = $this->path; |
77 | - if(count($this->values) > 0) { |
|
77 | + if (count($this->values) > 0) { |
|
78 | 78 | $s = http_build_query($this->values); |
79 | - if(strlen($s) > 0) { |
|
79 | + if (strlen($s) > 0) { |
|
80 | 80 | $p .= '?'.$s; |
81 | 81 | } |
82 | 82 | } |
@@ -100,17 +100,17 @@ discard block |
||
100 | 100 | { |
101 | 101 | $result = array(); |
102 | 102 | |
103 | - while(strlen($urlParameter) > 0) { |
|
103 | + while (strlen($urlParameter) > 0) { |
|
104 | 104 | // name |
105 | - $keyPosition= strpos($urlParameter,'='); |
|
106 | - $keyValue = substr($urlParameter,0,$keyPosition); |
|
105 | + $keyPosition = strpos($urlParameter, '='); |
|
106 | + $keyValue = substr($urlParameter, 0, $keyPosition); |
|
107 | 107 | // value |
108 | - $valuePosition = strpos($urlParameter,'&') ? strpos($urlParameter,'&'): strlen($urlParameter); |
|
109 | - $valueValue = substr($urlParameter,$keyPosition+1,$valuePosition-$keyPosition-1); |
|
108 | + $valuePosition = strpos($urlParameter, '&') ? strpos($urlParameter, '&') : strlen($urlParameter); |
|
109 | + $valueValue = substr($urlParameter, $keyPosition+1, $valuePosition-$keyPosition-1); |
|
110 | 110 | |
111 | 111 | // decoding the response |
112 | 112 | $result[$keyValue] = urldecode($valueValue); |
113 | - $urlParameter = substr($urlParameter,$valuePosition+1,strlen($urlParameter)); |
|
113 | + $urlParameter = substr($urlParameter, $valuePosition+1, strlen($urlParameter)); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | return $result; |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * @return null|int |
37 | 37 | */ |
38 | 38 | final public function getErrorCode() { |
39 | - if(false === $this->isSuccess()) { |
|
39 | + if (false === $this->isSuccess()) { |
|
40 | 40 | return $this->httpCode; |
41 | 41 | } |
42 | 42 | return null; |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @return string |
35 | 35 | */ |
36 | 36 | protected function getErrorMessageByErrorCode($httpCode) { |
37 | - switch($httpCode) { |
|
37 | + switch ($httpCode) { |
|
38 | 38 | case 401: |
39 | 39 | return 'API identity or secret incorrect or file is empty'; |
40 | 40 | case 402: |
@@ -247,8 +247,7 @@ |
||
247 | 247 | |
248 | 248 | $receiveResult->addFile('image', $filePath); |
249 | 249 | } |
250 | - } |
|
251 | - else if($message instanceof FileMessage) { |
|
250 | + } else if($message instanceof FileMessage) { |
|
252 | 251 | $result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage); |
253 | 252 | |
254 | 253 | if(null !== $result && true === $result->isSuccess()) { |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $this->cryptTool = $cryptTool; |
43 | 43 | $this->privateKey = $privateKey; |
44 | 44 | |
45 | - if(null === $this->cryptTool) { |
|
45 | + if (null === $this->cryptTool) { |
|
46 | 46 | $this->cryptTool = CryptTool::getInstance(); |
47 | 47 | } |
48 | 48 | } |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | //analyse the file |
85 | 85 | $fileAnalyzeResult = FileAnalysisTool::analyse($imagePath); |
86 | 86 | |
87 | - if(null === $fileAnalyzeResult) { |
|
87 | + if (null === $fileAnalyzeResult) { |
|
88 | 88 | throw new Exception('could not analyze the file'); |
89 | 89 | } |
90 | 90 | |
91 | - if(false === in_array($fileAnalyzeResult->getMimeType(), array( |
|
91 | + if (false === in_array($fileAnalyzeResult->getMimeType(), array( |
|
92 | 92 | 'image/jpg', |
93 | 93 | 'image/jpeg', |
94 | 94 | 'image/png' ))) { |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | //encrypt the image file |
104 | 104 | $encryptionResult = $this->cryptTool->encryptImage(file_get_contents($imagePath), $this->privateKey, $receiverPublicKey); |
105 | - $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
105 | + $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
106 | 106 | |
107 | - if($uploadResult === null || !$uploadResult->isSuccess()) { |
|
107 | + if ($uploadResult === null || !$uploadResult->isSuccess()) { |
|
108 | 108 | throw new Exception('could not upload the image ('.$uploadResult->getErrorCode().' '.$uploadResult->getErrorMessage().') '.$uploadResult->getRawResponse()); |
109 | 109 | } |
110 | 110 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | //analyse the file |
135 | 135 | $fileAnalyzeResult = FileAnalysisTool::analyse($filePath); |
136 | 136 | |
137 | - if(null === $fileAnalyzeResult) { |
|
137 | + if (null === $fileAnalyzeResult) { |
|
138 | 138 | throw new Exception('could not analyze the file'); |
139 | 139 | } |
140 | 140 | |
@@ -145,21 +145,21 @@ discard block |
||
145 | 145 | |
146 | 146 | //encrypt the main file |
147 | 147 | $encryptionResult = $this->cryptTool->encryptFile(file_get_contents($filePath)); |
148 | - $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
148 | + $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
149 | 149 | |
150 | - if($uploadResult === null || !$uploadResult->isSuccess()) { |
|
150 | + if ($uploadResult === null || !$uploadResult->isSuccess()) { |
|
151 | 151 | throw new Exception('could not upload the file ('.$uploadResult->getErrorCode().' '.$uploadResult->getErrorMessage().') '.$uploadResult->getRawResponse()); |
152 | 152 | } |
153 | 153 | |
154 | 154 | $thumbnailUploadResult = null; |
155 | 155 | |
156 | 156 | //encrypt the thumbnail file (if exists) |
157 | - if(strlen($thumbnailPath) > 0 && true === file_exists($thumbnailPath)) { |
|
157 | + if (strlen($thumbnailPath) > 0 && true === file_exists($thumbnailPath)) { |
|
158 | 158 | //encrypt the main file |
159 | 159 | $thumbnailEncryptionResult = $this->cryptTool->encryptFileThumbnail(file_get_contents($thumbnailPath), $encryptionResult->getKey()); |
160 | 160 | $thumbnailUploadResult = $this->connection->uploadFile($thumbnailEncryptionResult->getData()); |
161 | 161 | |
162 | - if($thumbnailUploadResult === null || !$thumbnailUploadResult->isSuccess()) { |
|
162 | + if ($thumbnailUploadResult === null || !$thumbnailUploadResult->isSuccess()) { |
|
163 | 163 | throw new Exception('could not upload the thumbnail file ('.$thumbnailUploadResult->getErrorCode().' '.$thumbnailUploadResult->getErrorMessage().') '.$thumbnailUploadResult->getRawResponse()); |
164 | 164 | } |
165 | 165 | } |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | $outputFolder = null, |
206 | 206 | \Closure $downloadMessage = null) { |
207 | 207 | |
208 | - if($outputFolder === null || strlen($outputFolder) == 0) { |
|
208 | + if ($outputFolder === null || strlen($outputFolder) == 0) { |
|
209 | 209 | $outputFolder = '.'; |
210 | 210 | } |
211 | 211 | |
212 | 212 | //fetch the public key |
213 | 213 | $receiverPublicKey = $this->connection->fetchPublicKey($threemaId); |
214 | 214 | |
215 | - if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
215 | + if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
216 | 216 | throw new Exception('Invalid threema id'); |
217 | 217 | } |
218 | 218 | |
@@ -223,15 +223,15 @@ discard block |
||
223 | 223 | $nonce |
224 | 224 | ); |
225 | 225 | |
226 | - if(null === $message || false === is_object($message)) { |
|
226 | + if (null === $message || false === is_object($message)) { |
|
227 | 227 | throw new Exception('Could not encrypt box'); |
228 | 228 | } |
229 | 229 | |
230 | 230 | $receiveResult = new ReceiveMessageResult($messageId, $message); |
231 | 231 | |
232 | - if($message instanceof ImageMessage) { |
|
232 | + if ($message instanceof ImageMessage) { |
|
233 | 233 | $result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage); |
234 | - if(null !== $result && true === $result->isSuccess()) { |
|
234 | + if (null !== $result && true === $result->isSuccess()) { |
|
235 | 235 | $image = $this->cryptTool->decryptImage( |
236 | 236 | $result->getData(), |
237 | 237 | $this->cryptTool->hex2bin($receiverPublicKey->getPublicKey()), |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | throw new Exception('decryption of image failed'); |
244 | 244 | } |
245 | 245 | //save file |
246 | - $filePath = $outputFolder . '/' . $messageId . '.jpg'; |
|
246 | + $filePath = $outputFolder.'/'.$messageId.'.jpg'; |
|
247 | 247 | $f = fopen($filePath, 'w+'); |
248 | 248 | fwrite($f, $image); |
249 | 249 | fclose($f); |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | $receiveResult->addFile('image', $filePath); |
252 | 252 | } |
253 | 253 | } |
254 | - else if($message instanceof FileMessage) { |
|
254 | + else if ($message instanceof FileMessage) { |
|
255 | 255 | $result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage); |
256 | 256 | |
257 | - if(null !== $result && true === $result->isSuccess()) { |
|
257 | + if (null !== $result && true === $result->isSuccess()) { |
|
258 | 258 | $file = $this->cryptTool->decryptFile( |
259 | 259 | $result->getData(), |
260 | 260 | hex2bin($message->getEncryptionKey())); |
@@ -264,20 +264,20 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | //save file |
267 | - $filePath = $outputFolder . '/' . $messageId . '-' . $message->getFilename(); |
|
267 | + $filePath = $outputFolder.'/'.$messageId.'-'.$message->getFilename(); |
|
268 | 268 | file_put_contents($filePath, $file); |
269 | 269 | |
270 | 270 | $receiveResult->addFile('file', $filePath); |
271 | 271 | } |
272 | 272 | |
273 | - if(null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) { |
|
273 | + if (null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) { |
|
274 | 274 | $result = $this->downloadFile($message, $message->getThumbnailBlobId(), $downloadMessage); |
275 | - if(null !== $result && true === $result->isSuccess()) { |
|
275 | + if (null !== $result && true === $result->isSuccess()) { |
|
276 | 276 | $file = $this->cryptTool->decryptFileThumbnail( |
277 | 277 | $result->getData(), |
278 | 278 | $this->cryptTool->hex2bin($message->getEncryptionKey())); |
279 | 279 | |
280 | - if(null === $file) { |
|
280 | + if (null === $file) { |
|
281 | 281 | throw new Exception('thumbnail decryption failed'); |
282 | 282 | } |
283 | 283 | //save file |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | //fetch the public key |
305 | 305 | $receiverPublicKey = $this->connection->fetchPublicKey($threemaId); |
306 | 306 | |
307 | - if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
307 | + if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
308 | 308 | throw new Exception('Invalid threema id'); |
309 | 309 | } |
310 | 310 | |
311 | - if(null !== $capabilityCheck) { |
|
311 | + if (null !== $capabilityCheck) { |
|
312 | 312 | //check capability |
313 | 313 | $capability = $this->connection->keyCapability($threemaId); |
314 | - if(null === $capability || false === $capabilityCheck->__invoke($capability)) { |
|
314 | + if (null === $capability || false === $capabilityCheck->__invoke($capability)) { |
|
315 | 315 | throw new Exception('threema id does not have the capability'); |
316 | 316 | } |
317 | 317 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | * @throws Exception |
328 | 328 | */ |
329 | 329 | private final function downloadFile(ThreemaMessage $message, $blobId, \Closure $downloadMessage = null) { |
330 | - if(null === $downloadMessage |
|
330 | + if (null === $downloadMessage |
|
331 | 331 | || true === $downloadMessage->__invoke($message, $blobId)) { |
332 | 332 | //make a download |
333 | 333 | $result = $this->connection->downloadFile($blobId); |
334 | - if(null === $result || false === $result->isSuccess()) { |
|
334 | + if (null === $result || false === $result->isSuccess()) { |
|
335 | 335 | throw new Exception('could not download the file with blob id '.$blobId); |
336 | 336 | } |
337 | 337 |
@@ -190,7 +190,7 @@ |
||
190 | 190 | * @param string $messageId |
191 | 191 | * @param string $box box as binary string |
192 | 192 | * @param string $nonce nonce as binary string |
193 | - * @param string|null|false $outputFolder folder for storing the files, |
|
193 | + * @param null|string $outputFolder folder for storing the files, |
|
194 | 194 | * null=current folder, false=do not download files |
195 | 195 | * @param \Closure $downloadMessage |
196 | 196 | * @return ReceiveMessageResult |