Completed
Pull Request — official (#17)
by rugk
02:34
created
source/Threema/MsgApi/Connection.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			}
202 202
 		}
203 203
 		if ($tlsCipher = $this->setting->getTlsOption(ConnectionSettings::tlsOptionCipher, null)) {
204
-			if(true === is_string($tlsCipher)) {
204
+			if (true === is_string($tlsCipher)) {
205 205
 				$options[CURLOPT_SSL_CIPHER_LIST] = $tlsCipher;
206 206
 			}
207 207
 		}
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 		return $this->call($command->getPath(),
234 234
 			$this->createDefaultOptions($progress),
235 235
 			$params,
236
-			function ($httpCode, $response) use ($command) {
236
+			function($httpCode, $response) use ($command) {
237 237
 				return $command->parseResult($httpCode, $response);
238 238
 			});
239 239
 	}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		$options[CURLOPT_HTTPHEADER] = array(
252 252
 			'Content-Type: application/x-www-form-urlencoded');
253 253
 
254
-		return $this->call($command->getPath(), $options, null, function ($httpCode, $response) use ($command) {
254
+		return $this->call($command->getPath(), $options, null, function($httpCode, $response) use ($command) {
255 255
 			return $command->parseResult($httpCode, $response);
256 256
 		});
257 257
 	}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 			'blob' => $command->getData()
272 272
 		);
273 273
 
274
-		return $this->call($command->getPath(), $options, $params, function ($httpCode, $response) use ($command) {
274
+		return $this->call($command->getPath(), $options, $params, function($httpCode, $response) use ($command) {
275 275
 			return $command->parseResult($httpCode, $response);
276 276
 		});
277 277
 	}
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 
299 299
 		$response = curl_exec($session);
300 300
 		if (false === $response) {
301
-			throw new Exception($path . ' ' . curl_error($session));
301
+			throw new Exception($path.' '.curl_error($session));
302 302
 		}
303 303
 
304 304
 		$httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
Please login to merge, or discard this patch.
source/Threema/MsgApi/ConnectionSettings.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi;
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,16 +48,16 @@
 block discarded – undo
48 48
 		$this->host = $host;
49 49
 
50 50
 		// TLS options
51
-		if(null !== $tlsOptions && is_array($tlsOptions)) {
52
-			if(true === array_key_exists(self::tlsOptionForceHttps, $tlsOptions)) {
51
+		if (null !== $tlsOptions && is_array($tlsOptions)) {
52
+			if (true === array_key_exists(self::tlsOptionForceHttps, $tlsOptions)) {
53 53
 				$this->tlsOptions[self::tlsOptionForceHttps] = $tlsOptions[self::tlsOptionForceHttps] === true;
54 54
 			}
55 55
 
56
-			if(true === array_key_exists(self::tlsOptionVersion, $tlsOptions)) {
56
+			if (true === array_key_exists(self::tlsOptionVersion, $tlsOptions)) {
57 57
 				$this->tlsOptions[self::tlsOptionVersion] = $tlsOptions[self::tlsOptionVersion];
58 58
 			}
59 59
 
60
-			if(true === array_key_exists(self::tlsOptionCipher, $tlsOptions)) {
60
+			if (true === array_key_exists(self::tlsOptionCipher, $tlsOptions)) {
61 61
 				$this->tlsOptions[self::tlsOptionCipher] = $tlsOptions[self::tlsOptionCipher];
62 62
 			}
63 63
 		}
Please login to merge, or discard this patch.
source/Threema/MsgApi/Constants.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Exceptions/BadMessageException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Exceptions;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Helpers/E2EHelper.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 										 $outputFolder = null,
203 203
 										 \Closure $downloadMessage = null) {
204 204
 
205
-		if($outputFolder == null || strlen($outputFolder) == 0) {
205
+		if ($outputFolder == null || strlen($outputFolder) == 0) {
206 206
 			$outputFolder = '.';
207 207
 		}
208 208
 
209 209
 		//fetch the public key
210 210
 		$receiverPublicKey = $this->connection->fetchPublicKey($threemaId);
211 211
 
212
-		if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) {
212
+		if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) {
213 213
 			throw new Exception('Invalid threema id');
214 214
 		}
215 215
 
@@ -220,15 +220,15 @@  discard block
 block discarded – undo
220 220
 			$nonce
221 221
 		);
222 222
 
223
-		if(null === $message || false === is_object($message)) {
223
+		if (null === $message || false === is_object($message)) {
224 224
 			throw new Exception('Could not encrypt box');
225 225
 		}
226 226
 
227 227
 		$receiveResult = new ReceiveMessageResult($messageId, $message);
228 228
 
229
-		if($message instanceof ImageMessage) {
229
+		if ($message instanceof ImageMessage) {
230 230
 			$result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage);
231
-			if(null !== $result && true === $result->isSuccess()) {
231
+			if (null !== $result && true === $result->isSuccess()) {
232 232
 				$image = $this->cryptTool->decryptImage(
233 233
 					$result->getData(),
234 234
 					hex2bin($receiverPublicKey->getPublicKey()),
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 					throw new Exception('decryption of image failed');
241 241
 				}
242 242
 				//save file
243
-				$filePath = $outputFolder . '/' . $messageId . '.jpg';
243
+				$filePath = $outputFolder.'/'.$messageId.'.jpg';
244 244
 				$f = fopen($filePath, 'w+');
245 245
 				fwrite($f, $image);
246 246
 				fclose($f);
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
 				$receiveResult->addFile('image', $filePath);
249 249
 			}
250 250
 		}
251
-		else if($message instanceof FileMessage) {
251
+		else if ($message instanceof FileMessage) {
252 252
 			$result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage);
253 253
 
254
-			if(null !== $result && true === $result->isSuccess()) {
254
+			if (null !== $result && true === $result->isSuccess()) {
255 255
 				$file = $this->cryptTool->decryptFile(
256 256
 					$result->getData(),
257 257
 					hex2bin($message->getEncryptionKey()));
@@ -261,20 +261,20 @@  discard block
 block discarded – undo
261 261
 				}
262 262
 
263 263
 				//save file
264
-				$filePath = $outputFolder . '/' . $messageId . '-' . $message->getFilename();
264
+				$filePath = $outputFolder.'/'.$messageId.'-'.$message->getFilename();
265 265
 				file_put_contents($filePath, $file);
266 266
 
267 267
 				$receiveResult->addFile('file', $filePath);
268 268
 			}
269 269
 
270
-			if(null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) {
270
+			if (null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) {
271 271
 				$result = $this->downloadFile($message, $message->getThumbnailBlobId(), $downloadMessage);
272
-				if(null !== $result && true === $result->isSuccess()) {
272
+				if (null !== $result && true === $result->isSuccess()) {
273 273
 					$file = $this->cryptTool->decryptFileThumbnail(
274 274
 						$result->getData(),
275 275
 						hex2bin($message->getEncryptionKey()));
276 276
 
277
-					if(null === $file) {
277
+					if (null === $file) {
278 278
 						throw new Exception('thumbnail decryption failed');
279 279
 					}
280 280
 					//save file
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
 		//fetch the public key
302 302
 		$receiverPublicKey = $this->connection->fetchPublicKey($threemaId);
303 303
 
304
-		if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) {
304
+		if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) {
305 305
 			throw new Exception('Invalid threema id');
306 306
 		}
307 307
 
308
-		if(null !== $capabilityCheck) {
308
+		if (null !== $capabilityCheck) {
309 309
 			//check capability
310 310
 			$capability = $this->connection->keyCapability($threemaId);
311
-			if(null === $capability || false === $capabilityCheck->__invoke($capability)) {
311
+			if (null === $capability || false === $capabilityCheck->__invoke($capability)) {
312 312
 				throw new Exception('threema id does not have the capability');
313 313
 			}
314 314
 		}
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
 	 * @throws Exception
325 325
 	 */
326 326
 	private final function downloadFile(ThreemaMessage $message, $blobId, \Closure $downloadMessage = null) {
327
-		if(null === $downloadMessage
327
+		if (null === $downloadMessage
328 328
 			|| true === $downloadMessage->__invoke($message, $blobId)) {
329 329
 			//make a download
330 330
 			$result = $this->connection->downloadFile($blobId);
331
-			if(null === $result || false === $result->isSuccess()) {
331
+			if (null === $result || false === $result->isSuccess()) {
332 332
 				throw new Exception('could not download the file with blob id '.$blobId);
333 333
 			}
334 334
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -247,8 +247,7 @@
 block discarded – undo
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()) {
Please login to merge, or discard this patch.
source/Threema/MsgApi/Messages/FileMessage.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Messages;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Messages/ImageMessage.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Messages;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Messages/TextMessage.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Messages;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Messages/ThreemaMessage.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Messages;
Please login to merge, or discard this patch.