Completed
Pull Request — master (#44)
by rugk
03:31 queued 58s
created
source/Threema/MsgApi/Commands/Results/UploadFileResult.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
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:
Please login to merge, or discard this patch.
source/Threema/MsgApi/Commands/UploadFile.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 	 * @param object $res
49 49
 	 * @return UploadFileResult
50 50
 	 */
51
-	function parseResult($httpCode, $res){
51
+	function parseResult($httpCode, $res) {
52 52
 		return new UploadFileResult($httpCode, $res);
53 53
 	}
54 54
 }
Please login to merge, or discard this patch.
source/Threema/MsgApi/Helpers/E2EHelper.php 2 patches
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.
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
 		}
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
source/Threema/MsgApi/PublicKeyStore.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@
 block discarded – undo
27 27
 	 * @return string|null
28 28
 	 */
29 29
 	public final function getPublicKey($threemaId) {
30
-		if(array_key_exists($threemaId, $this->cache)) {
30
+		if (array_key_exists($threemaId, $this->cache)) {
31 31
 			return $this->cache[$threemaId];
32 32
 		}
33 33
 
34 34
 		$publicKey = $this->findPublicKey($threemaId);
35
-		if(null !== $publicKey) {
35
+		if (null !== $publicKey) {
36 36
 			$this->cache[$threemaId] = $publicKey;
37 37
 		}
38 38
 		return $publicKey;
Please login to merge, or discard this patch.
source/Threema/MsgApi/PublicKeyStores/File.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@
 block discarded – undo
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)) {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * @throws Exception if the file does not exist or not writable
26 26
 	 */
27 27
 	public function __construct($file) {
28
-		if(false === is_writable($file)) {
28
+		if (false === is_writable($file)) {
29 29
 			throw new Exception('file '.$file.' does not exist or is not writable');
30 30
 		}
31 31
 		$this->file = $file;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	function findPublicKey($threemaId) {
41 41
 		$storeHandle = fopen($this->file, 'r');
42
-		if(false === $storeHandle) {
42
+		if (false === $storeHandle) {
43 43
 			throw new Exception('could not open file '.$this->file);
44 44
 		}
45 45
 		else {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			$publicKey = null;
48 48
 			while (!feof($storeHandle)) {
49 49
 				$buffer = fgets($storeHandle, 4096);
50
-				if(substr($buffer, 0, 8) == $threemaId) {
50
+				if (substr($buffer, 0, 8) == $threemaId) {
51 51
 					$publicKey = str_replace("\n", '', substr($buffer, 8));
52 52
 					continue;
53 53
 				}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 * @return File
75 75
 	 */
76 76
 	public static function create($path) {
77
-		if(false === file_exists($path)) {
77
+		if (false === file_exists($path)) {
78 78
 			//touch
79 79
 			touch($path);
80 80
 		}
Please login to merge, or discard this patch.
source/Threema/MsgApi/PublicKeyStores/PhpFile.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
 	public function __construct($file)
44 44
 	{
45 45
 		if (false === is_writable($file)) {
46
-			throw new Exception('file ' . $file . ' does not exist or is not writable');
46
+			throw new Exception('file '.$file.' does not exist or is not writable');
47 47
 		}
48 48
 		if (pathinfo($file, PATHINFO_EXTENSION) != 'php') {
49
-			throw new Exception('file ' . $file . ' is not a valid PHP file');
49
+			throw new Exception('file '.$file.' is not a valid PHP file');
50 50
 		}
51 51
 		$this->file = $file;
52 52
 	}
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 
105 105
 		//add key
106 106
 		$this->keystore[$threemaId] = $publicKey;
107
-		$content = '$keystore[\'' . $threemaId . '\'] = \'' . $publicKey . '\';' . PHP_EOL;
107
+		$content = '$keystore[\''.$threemaId.'\'] = \''.$publicKey.'\';'.PHP_EOL;
108 108
 
109 109
 		//write content
110 110
 		$fileadd = file_put_contents($this->file, $content, FILE_APPEND);
111 111
 		if (!$fileadd) {
112
-			throw new Exception('could not write to file ' . $this->file);
112
+			throw new Exception('could not write to file '.$this->file);
113 113
 		}
114 114
 
115 115
 		return true;
@@ -137,28 +137,28 @@  discard block
 block discarded – undo
137 137
 
138 138
 			//check for success
139 139
 			if (null === $fileHandle) {
140
-				throw new Exception('could not open file ' . $this->file);
140
+				throw new Exception('could not open file '.$this->file);
141 141
 			}
142 142
 		}
143 143
 
144 144
 		//create content
145
-		$content = $this->fileBlocker . PHP_EOL;
145
+		$content = $this->fileBlocker.PHP_EOL;
146 146
 		$content .= PHP_EOL;
147
-		$content .= '//Threema MsgApi phpfile keystore' . PHP_EOL;
148
-		$content .= '//DO NOT EDIT THIS FILE!' . PHP_EOL;
147
+		$content .= '//Threema MsgApi phpfile keystore'.PHP_EOL;
148
+		$content .= '//DO NOT EDIT THIS FILE!'.PHP_EOL;
149 149
 		$content .= PHP_EOL;
150 150
 
151 151
 		//write file
152 152
 		$fwrite = fwrite($fileHandle, $content);
153 153
 		if (!$fwrite) {
154
-			throw new Exception('could not write to file ' . $this->file);
154
+			throw new Exception('could not write to file '.$this->file);
155 155
 		}
156 156
 
157 157
 		//close file if necessary
158 158
 		if ($fileopened) {
159 159
 			$fclose = fclose($fileHandle);
160 160
 			if (!$fclose) {
161
-				throw new Exception('error while processing file ' . $this->file);
161
+				throw new Exception('error while processing file '.$this->file);
162 162
 			}
163 163
 		}
164 164
 		return true;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return PhpFile
171 171
 	 */
172 172
 	public static function create($path) {
173
-		if(false === file_exists($path)) {
173
+		if (false === file_exists($path)) {
174 174
 			//touch
175 175
 			touch($path);
176 176
 		}
Please login to merge, or discard this patch.
source/Threema/MsgApi/Receiver.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 	 * @throws \InvalidArgumentException
74 74
 	 */
75 75
 	public function getParams() {
76
-		switch($this->type) {
76
+		switch ($this->type) {
77 77
 			case self::TYPE_ID:
78 78
 				$to = $this->type;
79 79
 				$this->value = strtoupper(trim($this->value));
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/CryptToolSalt.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @return null|string
49 49
 	 */
50 50
 	protected function openBox($box, $recipientPrivateKey, $senderPublicKey, $nonce) {
51
-		$boxPad = str_repeat("\x00", 16) . $box;
51
+		$boxPad = str_repeat("\x00", 16).$box;
52 52
 		try {
53 53
 			$data = Salt::box_open($boxPad, $recipientPrivateKey, $senderPublicKey, $nonce);
54 54
 		} catch (\SaltException $e) {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * @return string as binary
72 72
 	 */
73 73
 	protected function openSecretBox($box, $nonce, $key) {
74
-		$boxPad = str_repeat("\x00", 16) . $box;
74
+		$boxPad = str_repeat("\x00", 16).$box;
75 75
 		$data = Salt::secretbox_open($boxPad, $nonce, $key);
76 76
 
77 77
 		if ($data) {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 			Salt::decodeInput($nonce),
131 131
 			$key);
132 132
 
133
-		if($data === false) {
133
+		if ($data === false) {
134 134
 			throw new Exception('encryption failed');
135 135
 		}
136 136
 
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 * @throws Exception
153 153
 	 */
154 154
 	public function validate() {
155
-		if(false === $this->isSupported()) {
155
+		if (false === $this->isSupported()) {
156 156
 			throw new Exception('SALT implementation not supported');
157 157
 		}
158 158
 
159
-		if(PHP_INT_SIZE < 8) {
159
+		if (PHP_INT_SIZE < 8) {
160 160
 			throw new Exception('Pure PHP Crypto implementation requires 64Bit PHP. Please install the libsodium PHP extension.');
161 161
 		}
162 162
 		return true;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/CryptToolSodiumDep.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@
 block discarded – undo
124 124
 	 * @throws Exception
125 125
 	 */
126 126
 	public function validate() {
127
-		if(false === $this->isSupported()) {
127
+		if (false === $this->isSupported()) {
128 128
 			throw new Exception('Sodium implementation not supported');
129 129
 		}
130 130
 		return true;
Please login to merge, or discard this patch.