Passed
Push — master ( 64ef8f...8a5223 )
by Malte
02:23
created
src/Folder.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 
124 124
         $this->setDelimiter($delimiter);
125 125
         $this->path      = $folder_name;
126
-        $this->full_name  = $this->decodeName($folder_name);
126
+        $this->full_name = $this->decodeName($folder_name);
127 127
         $this->name      = $this->getSimpleName($this->delimiter, $this->full_name);
128 128
 
129 129
         $this->parseAttributes($attributes);
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     public function move(string $new_name, bool $expunge = true): bool {
241 241
         $this->client->checkConnection();
242 242
         $status = $this->client->getConnection()->renameFolder($this->full_name, $new_name);
243
-        if($expunge) $this->client->expunge();
243
+        if ($expunge) $this->client->expunge();
244 244
 
245 245
         $folder = $this->client->getFolder($new_name);
246 246
         $event = $this->getEvent("folder", "moved");
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
          * date string that conforms to the rfc2060 specifications for a date_time value or be a Carbon object.
284 284
          */
285 285
 
286
-        if ($internal_date instanceof Carbon){
286
+        if ($internal_date instanceof Carbon) {
287 287
             $internal_date = $internal_date->format('d-M-Y H:i:s O');
288 288
         }
289 289
 
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      */
317 317
     public function delete(bool $expunge = true): bool {
318 318
         $status = $this->client->getConnection()->deleteFolder($this->path);
319
-        if($expunge) $this->client->expunge();
319
+        if ($expunge) $this->client->expunge();
320 320
 
321 321
         $event = $this->getEvent("folder", "deleted");
322 322
         $event::dispatch($this);
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 
382 382
                 if (($pos = strpos($line, "EXISTS")) !== false) {
383 383
                     $connection->done();
384
-                    $msgn = (int) substr($line, 2, $pos -2);
384
+                    $msgn = (int) substr($line, 2, $pos - 2);
385 385
 
386 386
                     $this->client->openFolder($this->path, true);
387 387
                     $message = $this->query()->getMessageByMsgn($msgn);
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
                     $connection->done();
396 396
                     $connection->idle();
397 397
                 }
398
-            }catch (Exceptions\RuntimeException $e) {
399
-                if(strpos($e->getMessage(), "empty response") >= 0 && $connection->connected()) {
398
+            } catch (Exceptions\RuntimeException $e) {
399
+                if (strpos($e->getMessage(), "empty response") >= 0 && $connection->connected()) {
400 400
                     $connection->done();
401 401
                     $connection->idle();
402 402
                     continue;
403 403
                 }
404
-                if(strpos($e->getMessage(), "connection closed") === false) {
404
+                if (strpos($e->getMessage(), "connection closed") === false) {
405 405
                     throw $e;
406 406
                 }
407 407
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
      * Set the delimiter
450 450
      * @param $delimiter
451 451
      */
452
-    public function setDelimiter($delimiter){
453
-        if(in_array($delimiter, [null, '', ' ', false]) === true) {
452
+    public function setDelimiter($delimiter) {
453
+        if (in_array($delimiter, [null, '', ' ', false]) === true) {
454 454
             $delimiter = ClientManager::get('options.delimiter', '/');
455 455
         }
456 456
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -240,7 +240,9 @@  discard block
 block discarded – undo
240 240
     public function move(string $new_name, bool $expunge = true): bool {
241 241
         $this->client->checkConnection();
242 242
         $status = $this->client->getConnection()->renameFolder($this->full_name, $new_name);
243
-        if($expunge) $this->client->expunge();
243
+        if($expunge) {
244
+            $this->client->expunge();
245
+        }
244 246
 
245 247
         $folder = $this->client->getFolder($new_name);
246 248
         $event = $this->getEvent("folder", "moved");
@@ -316,7 +318,9 @@  discard block
 block discarded – undo
316 318
      */
317 319
     public function delete(bool $expunge = true): bool {
318 320
         $status = $this->client->getConnection()->deleteFolder($this->path);
319
-        if($expunge) $this->client->expunge();
321
+        if($expunge) {
322
+            $this->client->expunge();
323
+        }
320 324
 
321 325
         $event = $this->getEvent("folder", "deleted");
322 326
         $event::dispatch($this);
@@ -395,7 +399,7 @@  discard block
 block discarded – undo
395 399
                     $connection->done();
396 400
                     $connection->idle();
397 401
                 }
398
-            }catch (Exceptions\RuntimeException $e) {
402
+            } catch (Exceptions\RuntimeException $e) {
399 403
                 if(strpos($e->getMessage(), "empty response") >= 0 && $connection->connected()) {
400 404
                     $connection->done();
401 405
                     $connection->idle();
Please login to merge, or discard this patch.
src/Connection/Protocols/ImapProtocol.php 2 patches
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -111,7 +111,9 @@  discard block
 block discarded – undo
111 111
         if ($line === "") {
112 112
             throw new RuntimeException('empty response');
113 113
         }
114
-        if ($this->debug) echo "<< ".$line."\n";
114
+        if ($this->debug) {
115
+            echo "<< ".$line."\n";
116
+        }
115 117
         return $line . "\n";
116 118
     }
117 119
 
@@ -325,7 +327,9 @@  discard block
 block discarded – undo
325 327
      * @throws RuntimeException
326 328
      */
327 329
     public function write(string $data) {
328
-        if ($this->debug) echo ">> ".$data ."\n";
330
+        if ($this->debug) {
331
+            echo ">> ".$data ."\n";
332
+        }
329 333
 
330 334
         if (fwrite($this->stream, $data . "\r\n") === false) {
331 335
             throw new RuntimeException('failed to write - connection closed?');
@@ -477,7 +481,9 @@  discard block
 block discarded – undo
477 481
     public function getCapabilities(): array {
478 482
         $response = $this->requestAndResponse('CAPABILITY');
479 483
 
480
-        if (!$response) return [];
484
+        if (!$response) {
485
+            return [];
486
+        }
481 487
 
482 488
         $capabilities = [];
483 489
         foreach ($response as $line) {
@@ -637,13 +643,14 @@  discard block
 block discarded – undo
637 643
             // if we want only one message we can ignore everything else and just return
638 644
             if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {
639 645
                 // we still need to read all lines
640
-                while (!$this->readLine($tokens, $tag))
641
-
646
+                while (!$this->readLine($tokens, $tag)) {
647
+                
642 648
                     return $data;
649
+                }
643 650
             }
644 651
             if ($uid) {
645 652
                 $result[$tokens[2][$uidKey]] = $data;
646
-            }else{
653
+            } else{
647 654
                 $result[$tokens[0]] = $data;
648 655
             }
649 656
         }
@@ -1073,7 +1080,9 @@  discard block
 block discarded – undo
1073 1080
     public function search(array $params, $uid = IMAP::ST_UID): array {
1074 1081
         $command = $this->buildUIDCommand("SEARCH", $uid);
1075 1082
         $response = $this->requestAndResponse($command, $params);
1076
-        if (!$response) return [];
1083
+        if (!$response) {
1084
+            return [];
1085
+        }
1077 1086
 
1078 1087
         foreach ($response as $ids) {
1079 1088
             if ($ids[0] == 'SEARCH') {
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * @throws ConnectionFailedException
90 90
      * @throws RuntimeException
91 91
      */
92
-    protected function enableStartTls(){
92
+    protected function enableStartTls() {
93 93
         $response = $this->requestAndResponse('STARTTLS');
94 94
         $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod());
95 95
         if (!$result) {
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
             throw new RuntimeException('empty response');
113 113
         }
114 114
         if ($this->debug) echo "<< ".$line."\n";
115
-        return $line . "\n";
115
+        return $line."\n";
116 116
     }
117 117
 
118 118
     /**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
         $stack = [];
166 166
 
167 167
         //  replace any trailing <NL> including spaces with a single space
168
-        $line = rtrim($line) . ' ';
168
+        $line = rtrim($line).' ';
169 169
         while (($pos = strpos($line, ' ')) !== false) {
170 170
             $token = substr($line, 0, $pos);
171 171
             if (!strlen($token)) {
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
                     if (strlen($token) > $chars) {
196 196
                         $line = substr($token, $chars);
197 197
                         $token = substr($token, 0, $chars);
198
-                    } else {
198
+                    }else {
199 199
                         $line .= $this->nextLine();
200 200
                     }
201 201
                     $tokens[] = $token;
202
-                    $line = trim($line) . ' ';
202
+                    $line = trim($line).' ';
203 203
                     continue;
204 204
                 }
205 205
             }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         $line = $this->nextTaggedLine($tag); // get next tag
250 250
         if (!$dontParse) {
251 251
             $tokens = $this->decodeLine($line);
252
-        } else {
252
+        }else {
253 253
             $tokens = $line;
254 254
         }
255 255
 
@@ -299,20 +299,20 @@  discard block
 block discarded – undo
299 299
     public function sendRequest(string $command, array $tokens = [], string &$tag = null) {
300 300
         if (!$tag) {
301 301
             $this->noun++;
302
-            $tag = 'TAG' . $this->noun;
302
+            $tag = 'TAG'.$this->noun;
303 303
         }
304 304
 
305
-        $line = $tag . ' ' . $command;
305
+        $line = $tag.' '.$command;
306 306
 
307 307
         foreach ($tokens as $token) {
308 308
             if (is_array($token)) {
309
-                $this->write($line . ' ' . $token[0]);
309
+                $this->write($line.' '.$token[0]);
310 310
                 if (!$this->assumedNextLine('+ ')) {
311 311
                     throw new RuntimeException('failed to send literal string');
312 312
                 }
313 313
                 $line = $token[1];
314
-            } else {
315
-                $line .= ' ' . $token;
314
+            }else {
315
+                $line .= ' '.$token;
316 316
             }
317 317
         }
318 318
         $this->write($line);
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
      * @throws RuntimeException
326 326
      */
327 327
     public function write(string $data) {
328
-        if ($this->debug) echo ">> ".$data ."\n";
328
+        if ($this->debug) echo ">> ".$data."\n";
329 329
 
330
-        if (fwrite($this->stream, $data . "\r\n") === false) {
330
+        if (fwrite($this->stream, $data."\r\n") === false) {
331 331
             throw new RuntimeException('failed to write - connection closed?');
332 332
         }
333 333
     }
@@ -357,9 +357,9 @@  discard block
 block discarded – undo
357 357
     public function escapeString($string) {
358 358
         if (func_num_args() < 2) {
359 359
             if (strpos($string, "\n") !== false) {
360
-                return ['{' . strlen($string) . '}', $string];
361
-            } else {
362
-                return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"';
360
+                return ['{'.strlen($string).'}', $string];
361
+            }else {
362
+                return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"';
363 363
             }
364 364
         }
365 365
         $result = [];
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
             }
385 385
             $result[] = $this->escapeList($v);
386 386
         }
387
-        return '(' . implode(' ', $result) . ')';
387
+        return '('.implode(' ', $result).')';
388 388
     }
389 389
 
390 390
     /**
@@ -425,12 +425,12 @@  discard block
 block discarded – undo
425 425
                     error_log("got an extra server challenge: $response");
426 426
                     // respond with an empty response.
427 427
                     $this->sendRequest('');
428
-                } else {
428
+                }else {
429 429
                     if (preg_match('/^NO /i', $response) ||
430 430
                         preg_match('/^BAD /i', $response)) {
431 431
                         error_log("got failure response: $response");
432 432
                         return false;
433
-                    } else if (preg_match("/^OK /i", $response)) {
433
+                    }else if (preg_match("/^OK /i", $response)) {
434 434
                         return true;
435 435
                     }
436 436
                 }
@@ -511,10 +511,10 @@  discard block
 block discarded – undo
511 511
                     $result[strtolower($tokens[1])] = $tokens[0];
512 512
                     break;
513 513
                 case '[UIDVALIDITY':
514
-                    $result['uidvalidity'] = (int)$tokens[2];
514
+                    $result['uidvalidity'] = (int) $tokens[2];
515 515
                     break;
516 516
                 case '[UIDNEXT':
517
-                    $result['uidnext'] = (int)$tokens[2];
517
+                    $result['uidnext'] = (int) $tokens[2];
518 518
                     break;
519 519
                 case '[NONEXISTENT]':
520 520
                     throw new RuntimeException("folder doesn't exist");
@@ -573,14 +573,14 @@  discard block
 block discarded – undo
573 573
         if (is_array($from)) {
574 574
             $set = implode(',', $from);
575 575
         } elseif ($to === null) {
576
-            $set = (int)$from;
576
+            $set = (int) $from;
577 577
         } elseif ($to === INF) {
578
-            $set = (int)$from . ':*';
579
-        } else {
580
-            $set = (int)$from . ':' . (int)$to;
578
+            $set = (int) $from.':*';
579
+        }else {
580
+            $set = (int) $from.':'.(int) $to;
581 581
         }
582 582
 
583
-        $items = (array)$items;
583
+        $items = (array) $items;
584 584
         $itemList = $this->escapeList($items);
585 585
 
586 586
         $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag);
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
                 $count = count($tokens[2]);
598 598
                 if ($tokens[2][$count - 2] == 'UID') {
599 599
                     $uidKey = $count - 1;
600
-                } else if ($tokens[2][0] == 'UID') {
600
+                }else if ($tokens[2][0] == 'UID') {
601 601
                     $uidKey = 1;
602
-                } else {
602
+                }else {
603 603
                     $found = array_search('UID', $tokens[2]);
604 604
                     if ($found === false || $found === -1) {
605 605
                         continue;
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
                     $data = $tokens[2][1];
622 622
                 } elseif ($uid && $tokens[2][2] == $items[0]) {
623 623
                     $data = $tokens[2][3];
624
-                } else {
624
+                }else {
625 625
                     // maybe the server send an other field we didn't wanted
626 626
                     $count = count($tokens[2]);
627 627
                     // we start with 2, because 0 was already checked
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
                         break;
634 634
                     }
635 635
                 }
636
-            } else {
636
+            }else {
637 637
                 $data = [];
638 638
                 while (key($tokens[2]) !== null) {
639 639
                     $data[current($tokens[2])] = next($tokens[2]);
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
             }
651 651
             if ($uid) {
652 652
                 $result[$tokens[2][$uidKey]] = $data;
653
-            }else{
653
+            }else {
654 654
                 $result[$tokens[0]] = $data;
655 655
             }
656 656
         }
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
         $ids = $this->getUid();
752 752
         foreach ($ids as $k => $v) {
753 753
             if ($v == $id) {
754
-                return (int)$k;
754
+                return (int) $k;
755 755
             }
756 756
         }
757 757
 
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
         $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent);
809 809
 
810 810
         if ($silent) {
811
-            return (bool)$response;
811
+            return (bool) $response;
812 812
         }
813 813
 
814 814
         $result = [];
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
     public function copyMessage(string $folder, $from, $to = null, $uid = IMAP::ST_UID): bool {
862 862
         $set = $this->buildSet($from, $to);
863 863
         $command = $this->buildUIDCommand("COPY", $uid);
864
-        return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
864
+        return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
865 865
     }
866 866
 
867 867
     /**
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
         $set = $this->buildSet($from, $to);
901 901
         $command = $this->buildUIDCommand("MOVE", $uid);
902 902
 
903
-        return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
903
+        return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
904 904
     }
905 905
 
906 906
     /**
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
      * @throws RuntimeException
953 953
      */
954 954
     public function createFolder(string $folder): bool {
955
-        return (bool)$this->requestAndResponse('CREATE', [$this->escapeString($folder)], true);
955
+        return (bool) $this->requestAndResponse('CREATE', [$this->escapeString($folder)], true);
956 956
     }
957 957
 
958 958
     /**
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
      * @throws RuntimeException
965 965
      */
966 966
     public function renameFolder(string $old, string $new): bool {
967
-        return (bool)$this->requestAndResponse('RENAME', $this->escapeString($old, $new), true);
967
+        return (bool) $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true);
968 968
     }
969 969
 
970 970
     /**
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
      * @throws RuntimeException
976 976
      */
977 977
     public function deleteFolder(string $folder): bool {
978
-        return (bool)$this->requestAndResponse('DELETE', [$this->escapeString($folder)], true);
978
+        return (bool) $this->requestAndResponse('DELETE', [$this->escapeString($folder)], true);
979 979
     }
980 980
 
981 981
     /**
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
      * @throws RuntimeException
987 987
      */
988 988
     public function subscribeFolder(string $folder): bool {
989
-        return (bool)$this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true);
989
+        return (bool) $this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true);
990 990
     }
991 991
 
992 992
     /**
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
      * @throws RuntimeException
998 998
      */
999 999
     public function unsubscribeFolder(string $folder): bool {
1000
-        return (bool)$this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true);
1000
+        return (bool) $this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true);
1001 1001
     }
1002 1002
 
1003 1003
     /**
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
      * @throws RuntimeException
1008 1008
      */
1009 1009
     public function expunge(): bool {
1010
-        return (bool)$this->requestAndResponse('EXPUNGE');
1010
+        return (bool) $this->requestAndResponse('EXPUNGE');
1011 1011
     }
1012 1012
 
1013 1013
     /**
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
      * @throws RuntimeException
1018 1018
      */
1019 1019
     public function noop(): bool {
1020
-        return (bool)$this->requestAndResponse('NOOP');
1020
+        return (bool) $this->requestAndResponse('NOOP');
1021 1021
     }
1022 1022
 
1023 1023
     /**
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
         $ids = [];
1111 1111
         foreach ($uids as $msgn => $v) {
1112 1112
             $id = $uid ? $v : $msgn;
1113
-            if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){
1113
+            if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) {
1114 1114
                 $ids[] = $id;
1115 1115
             }
1116 1116
         }
@@ -1124,14 +1124,14 @@  discard block
 block discarded – undo
1124 1124
     /**
1125 1125
      * Enable the debug mode
1126 1126
      */
1127
-    public function enableDebug(){
1127
+    public function enableDebug() {
1128 1128
         $this->debug = true;
1129 1129
     }
1130 1130
 
1131 1131
     /**
1132 1132
      * Disable the debug mode
1133 1133
      */
1134
-    public function disableDebug(){
1134
+    public function disableDebug() {
1135 1135
         $this->debug = false;
1136 1136
     }
1137 1137
 
@@ -1143,9 +1143,9 @@  discard block
 block discarded – undo
1143 1143
      * @return int|string
1144 1144
      */
1145 1145
     public function buildSet($from, $to = null) {
1146
-        $set = (int)$from;
1146
+        $set = (int) $from;
1147 1147
         if ($to !== null) {
1148
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
1148
+            $set .= ':'.($to == INF ? '*' : (int) $to);
1149 1149
         }
1150 1150
         return $set;
1151 1151
     }
Please login to merge, or discard this patch.