Passed
Push — master ( fbc5b7...d88edd )
by Malte
03:02
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
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
                 default:
520 520
                     // ignore
@@ -571,14 +571,14 @@  discard block
 block discarded – undo
571 571
         if (is_array($from)) {
572 572
             $set = implode(',', $from);
573 573
         } elseif ($to === null) {
574
-            $set = (int)$from;
574
+            $set = (int) $from;
575 575
         } elseif ($to === INF) {
576
-            $set = (int)$from . ':*';
577
-        } else {
578
-            $set = (int)$from . ':' . (int)$to;
576
+            $set = (int) $from.':*';
577
+        }else {
578
+            $set = (int) $from.':'.(int) $to;
579 579
         }
580 580
 
581
-        $items = (array)$items;
581
+        $items = (array) $items;
582 582
         $itemList = $this->escapeList($items);
583 583
 
584 584
         $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag);
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
                 $count = count($tokens[2]);
596 596
                 if ($tokens[2][$count - 2] == 'UID') {
597 597
                     $uidKey = $count - 1;
598
-                } else if ($tokens[2][0] == 'UID') {
598
+                }else if ($tokens[2][0] == 'UID') {
599 599
                     $uidKey = 1;
600
-                } else {
600
+                }else {
601 601
                     $uidKey = array_search('UID', $tokens[2]) + 1;
602 602
                 }
603 603
             }
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
                     $data = $tokens[2][1];
615 615
                 } elseif ($uid && $tokens[2][2] == $items[0]) {
616 616
                     $data = $tokens[2][3];
617
-                } else {
617
+                }else {
618 618
                     // maybe the server send an other field we didn't wanted
619 619
                     $count = count($tokens[2]);
620 620
                     // we start with 2, because 0 was already checked
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
                         break;
627 627
                     }
628 628
                 }
629
-            } else {
629
+            }else {
630 630
                 $data = [];
631 631
                 while (key($tokens[2]) !== null) {
632 632
                     $data[current($tokens[2])] = next($tokens[2]);
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
             }
644 644
             if ($uid) {
645 645
                 $result[$tokens[2][$uidKey]] = $data;
646
-            }else{
646
+            }else {
647 647
                 $result[$tokens[0]] = $data;
648 648
             }
649 649
         }
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
         $ids = $this->getUid();
745 745
         foreach ($ids as $k => $v) {
746 746
             if ($v == $id) {
747
-                return (int)$k;
747
+                return (int) $k;
748 748
             }
749 749
         }
750 750
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent);
802 802
 
803 803
         if ($silent) {
804
-            return (bool)$response;
804
+            return (bool) $response;
805 805
         }
806 806
 
807 807
         $result = [];
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
     public function copyMessage(string $folder, $from, $to = null, $uid = IMAP::ST_UID): bool {
855 855
         $set = $this->buildSet($from, $to);
856 856
         $command = $this->buildUIDCommand("COPY", $uid);
857
-        return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
857
+        return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
858 858
     }
859 859
 
860 860
     /**
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
         $set = $this->buildSet($from, $to);
894 894
         $command = $this->buildUIDCommand("MOVE", $uid);
895 895
 
896
-        return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
896
+        return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
897 897
     }
898 898
 
899 899
     /**
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
      * @throws RuntimeException
946 946
      */
947 947
     public function createFolder(string $folder): bool {
948
-        return (bool)$this->requestAndResponse('CREATE', [$this->escapeString($folder)], true);
948
+        return (bool) $this->requestAndResponse('CREATE', [$this->escapeString($folder)], true);
949 949
     }
950 950
 
951 951
     /**
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
      * @throws RuntimeException
958 958
      */
959 959
     public function renameFolder(string $old, string $new): bool {
960
-        return (bool)$this->requestAndResponse('RENAME', $this->escapeString($old, $new), true);
960
+        return (bool) $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true);
961 961
     }
962 962
 
963 963
     /**
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
      * @throws RuntimeException
969 969
      */
970 970
     public function deleteFolder(string $folder): bool {
971
-        return (bool)$this->requestAndResponse('DELETE', [$this->escapeString($folder)], true);
971
+        return (bool) $this->requestAndResponse('DELETE', [$this->escapeString($folder)], true);
972 972
     }
973 973
 
974 974
     /**
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
      * @throws RuntimeException
980 980
      */
981 981
     public function subscribeFolder(string $folder): bool {
982
-        return (bool)$this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true);
982
+        return (bool) $this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true);
983 983
     }
984 984
 
985 985
     /**
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
      * @throws RuntimeException
991 991
      */
992 992
     public function unsubscribeFolder(string $folder): bool {
993
-        return (bool)$this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true);
993
+        return (bool) $this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true);
994 994
     }
995 995
 
996 996
     /**
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
      * @throws RuntimeException
1001 1001
      */
1002 1002
     public function expunge(): bool {
1003
-        return (bool)$this->requestAndResponse('EXPUNGE');
1003
+        return (bool) $this->requestAndResponse('EXPUNGE');
1004 1004
     }
1005 1005
 
1006 1006
     /**
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
      * @throws RuntimeException
1011 1011
      */
1012 1012
     public function noop(): bool {
1013
-        return (bool)$this->requestAndResponse('NOOP');
1013
+        return (bool) $this->requestAndResponse('NOOP');
1014 1014
     }
1015 1015
 
1016 1016
     /**
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
         $ids = [];
1104 1104
         foreach ($uids as $msgn => $v) {
1105 1105
             $id = $uid ? $v : $msgn;
1106
-            if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){
1106
+            if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) {
1107 1107
                 $ids[] = $id;
1108 1108
             }
1109 1109
         }
@@ -1117,14 +1117,14 @@  discard block
 block discarded – undo
1117 1117
     /**
1118 1118
      * Enable the debug mode
1119 1119
      */
1120
-    public function enableDebug(){
1120
+    public function enableDebug() {
1121 1121
         $this->debug = true;
1122 1122
     }
1123 1123
 
1124 1124
     /**
1125 1125
      * Disable the debug mode
1126 1126
      */
1127
-    public function disableDebug(){
1127
+    public function disableDebug() {
1128 1128
         $this->debug = false;
1129 1129
     }
1130 1130
 
@@ -1136,9 +1136,9 @@  discard block
 block discarded – undo
1136 1136
      * @return int|string
1137 1137
      */
1138 1138
     public function buildSet($from, $to = null) {
1139
-        $set = (int)$from;
1139
+        $set = (int) $from;
1140 1140
         if ($to !== null) {
1141
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
1141
+            $set .= ':'.($to == INF ? '*' : (int) $to);
1142 1142
         }
1143 1143
         return $set;
1144 1144
     }
Please login to merge, or discard this patch.
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.