Completed
Push — master ( 4995a3...c888a3 )
by Malte
01:44
created
src/Connection/Protocols/ImapProtocol.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @throws ConnectionFailedException
83 83
      * @throws RuntimeException
84 84
      */
85
-    protected function enableTls(){
85
+    protected function enableTls() {
86 86
         $response = $this->requestAndResponse('STARTTLS');
87 87
         $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod());
88 88
         if (!$result) {
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         $stack = [];
145 145
 
146 146
         //  replace any trailing <NL> including spaces with a single space
147
-        $line = rtrim($line) . ' ';
147
+        $line = rtrim($line).' ';
148 148
         while (($pos = strpos($line, ' ')) !== false) {
149 149
             $token = substr($line, 0, $pos);
150 150
             if (!strlen($token)) {
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
                     if (strlen($token) > $chars) {
175 175
                         $line = substr($token, $chars);
176 176
                         $token = substr($token, 0, $chars);
177
-                    } else {
177
+                    }else {
178 178
                         $line .= $this->nextLine();
179 179
                     }
180 180
                     $tokens[] = $token;
181
-                    $line = trim($line) . ' ';
181
+                    $line = trim($line).' ';
182 182
                     continue;
183 183
                 }
184 184
             }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         $line = $this->nextTaggedLine($tag); // get next tag
229 229
         if (!$dontParse) {
230 230
             $tokens = $this->decodeLine($line);
231
-        } else {
231
+        }else {
232 232
             $tokens = $line;
233 233
         }
234 234
 
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
             // last to chars are still needed for response code
256 256
             $tokens = [substr($tokens, 0, 2)];
257 257
         }
258
-        if (is_array($lines)){
258
+        if (is_array($lines)) {
259 259
             if ($this->debug) echo "<< ".json_encode($lines)."\n";
260
-        }else{
260
+        }else {
261 261
             if ($this->debug) echo "<< ".$lines."\n";
262 262
         }
263 263
         // last line has response code
@@ -280,27 +280,27 @@  discard block
 block discarded – undo
280 280
     public function sendRequest($command, $tokens = [], &$tag = null) {
281 281
         if (!$tag) {
282 282
             $this->noun++;
283
-            $tag = 'TAG' . $this->noun;
283
+            $tag = 'TAG'.$this->noun;
284 284
         }
285 285
 
286
-        $line = $tag . ' ' . $command;
286
+        $line = $tag.' '.$command;
287 287
 
288 288
         foreach ($tokens as $token) {
289 289
             if (is_array($token)) {
290
-                if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) {
290
+                if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) {
291 291
                     throw new RuntimeException('failed to write - connection closed?');
292 292
                 }
293 293
                 if (!$this->assumedNextLine('+ ')) {
294 294
                     throw new RuntimeException('failed to send literal string');
295 295
                 }
296 296
                 $line = $token[1];
297
-            } else {
298
-                $line .= ' ' . $token;
297
+            }else {
298
+                $line .= ' '.$token;
299 299
             }
300 300
         }
301 301
         if ($this->debug) echo ">> ".$line."\n";
302 302
 
303
-        if (fwrite($this->stream, $line . "\r\n") === false) {
303
+        if (fwrite($this->stream, $line."\r\n") === false) {
304 304
             throw new RuntimeException('failed to write - connection closed?');
305 305
         }
306 306
     }
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
     public function escapeString($string) {
331 331
         if (func_num_args() < 2) {
332 332
             if (strpos($string, "\n") !== false) {
333
-                return ['{' . strlen($string) . '}', $string];
334
-            } else {
335
-                return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"';
333
+                return ['{'.strlen($string).'}', $string];
334
+            }else {
335
+                return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"';
336 336
             }
337 337
         }
338 338
         $result = [];
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
             }
358 358
             $result[] = $this->escapeList($v);
359 359
         }
360
-        return '(' . implode(' ', $result) . ')';
360
+        return '('.implode(' ', $result).')';
361 361
     }
362 362
 
363 363
     /**
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
                     error_log("got an extra server challenge: $response");
398 398
                     // respond with an empty response.
399 399
                     $this->sendRequest('');
400
-                } else {
400
+                }else {
401 401
                     if (preg_match('/^NO /i', $response) ||
402 402
                         preg_match('/^BAD /i', $response)) {
403 403
                         error_log("got failure response: $response");
404 404
                         return false;
405
-                    } else if (preg_match("/^OK /i", $response)) {
405
+                    }else if (preg_match("/^OK /i", $response)) {
406 406
                         return true;
407 407
                     }
408 408
                 }
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
      *
436 436
      * @return bool
437 437
      */
438
-    public function connected(){
438
+    public function connected() {
439 439
         return (boolean) $this->stream;
440 440
     }
441 441
 
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
                     $result[strtolower($tokens[1])] = $tokens[0];
483 483
                     break;
484 484
                 case '[UIDVALIDITY':
485
-                    $result['uidvalidity'] = (int)$tokens[2];
485
+                    $result['uidvalidity'] = (int) $tokens[2];
486 486
                     break;
487 487
                 case '[UIDNEXT':
488
-                    $result['uidnext'] = (int)$tokens[2];
488
+                    $result['uidnext'] = (int) $tokens[2];
489 489
                     break;
490 490
                 default:
491 491
                     // ignore
@@ -539,17 +539,17 @@  discard block
 block discarded – undo
539 539
         if (is_array($from)) {
540 540
             $set = implode(',', $from);
541 541
         } elseif ($to === null) {
542
-            $set = (int)$from;
542
+            $set = (int) $from;
543 543
         } elseif ($to === INF) {
544
-            $set = (int)$from . ':*';
545
-        } else {
546
-            $set = (int)$from . ':' . (int)$to;
544
+            $set = (int) $from.':*';
545
+        }else {
546
+            $set = (int) $from.':'.(int) $to;
547 547
         }
548 548
 
549
-        $items = (array)$items;
549
+        $items = (array) $items;
550 550
         $itemList = $this->escapeList($items);
551 551
 
552
-        $this->sendRequest(($uid ? 'UID ' : '') . 'FETCH', [$set, $itemList], $tag);
552
+        $this->sendRequest(($uid ? 'UID ' : '').'FETCH', [$set, $itemList], $tag);
553 553
 
554 554
         $result = [];
555 555
         $tokens = null; // define $tokens variable before first use
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                 $count = count($tokens[2]);
565 565
                 if ($tokens[2][$count - 2] == 'UID') {
566 566
                     $uidKey = $count - 1;
567
-                } else {
567
+                }else {
568 568
                     $uidKey = array_search('UID', $tokens[2]) + 1;
569 569
                 }
570 570
             }
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                     $data = $tokens[2][1];
581 581
                 } elseif ($uid && $tokens[2][2] == $items[0]) {
582 582
                     $data = $tokens[2][3];
583
-                } else {
583
+                }else {
584 584
                     // maybe the server send an other field we didn't wanted
585 585
                     $count = count($tokens[2]);
586 586
                     // we start with 2, because 0 was already checked
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
                         break;
593 593
                     }
594 594
                 }
595
-            } else {
595
+            }else {
596 596
                 $data = [];
597 597
                 while (key($tokens[2]) !== null) {
598 598
                     $data[current($tokens[2])] = next($tokens[2]);
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
      * @return array
638 638
      * @throws RuntimeException
639 639
      */
640
-    public function headers($uids, $rfc = "RFC822"){
640
+    public function headers($uids, $rfc = "RFC822") {
641 641
         return $this->fetch(["$rfc.HEADER"], $uids);
642 642
     }
643 643
 
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
      * @return array
649 649
      * @throws RuntimeException
650 650
      */
651
-    public function flags($uids){
651
+    public function flags($uids) {
652 652
         return $this->fetch(["FLAGS"], $uids);
653 653
     }
654 654
 
@@ -732,22 +732,22 @@  discard block
 block discarded – undo
732 732
     public function store(array $flags, $from, $to = null, $mode = null, $silent = true) {
733 733
         $item = 'FLAGS';
734 734
         if ($mode == '+' || $mode == '-') {
735
-            $item = $mode . $item;
735
+            $item = $mode.$item;
736 736
         }
737 737
         if ($silent) {
738 738
             $item .= '.SILENT';
739 739
         }
740 740
 
741 741
         $flags = $this->escapeList($flags);
742
-        $set = (int)$from;
742
+        $set = (int) $from;
743 743
         if ($to !== null) {
744
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
744
+            $set .= ':'.($to == INF ? '*' : (int) $to);
745 745
         }
746 746
 
747 747
         $result = $this->requestAndResponse('STORE', [$set, $item, $flags], $silent);
748 748
 
749 749
         if ($silent) {
750
-            return (bool)$result;
750
+            return (bool) $result;
751 751
         }
752 752
 
753 753
         $tokens = $result;
@@ -797,9 +797,9 @@  discard block
 block discarded – undo
797 797
      * @throws RuntimeException
798 798
      */
799 799
     public function copyMessage($folder, $from, $to = null) {
800
-        $set = (int)$from;
800
+        $set = (int) $from;
801 801
         if ($to !== null) {
802
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
802
+            $set .= ':'.($to == INF ? '*' : (int) $to);
803 803
         }
804 804
 
805 805
         return $this->requestAndResponse('COPY', [$set, $this->escapeString($folder)], true);
@@ -816,9 +816,9 @@  discard block
 block discarded – undo
816 816
      * @throws RuntimeException
817 817
      */
818 818
     public function moveMessage($folder, $from, $to = null) {
819
-        $set = (int)$from;
819
+        $set = (int) $from;
820 820
         if ($to !== null) {
821
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
821
+            $set .= ':'.($to == INF ? '*' : (int) $to);
822 822
         }
823 823
 
824 824
         return $this->requestAndResponse('MOVE', [$set, $this->escapeString($folder)], true);
@@ -969,14 +969,14 @@  discard block
 block discarded – undo
969 969
     /**
970 970
      * Enable the debug mode
971 971
      */
972
-    public function enableDebug(){
972
+    public function enableDebug() {
973 973
         $this->debug = true;
974 974
     }
975 975
 
976 976
     /**
977 977
      * Disable the debug mode
978 978
      */
979
-    public function disableDebug(){
979
+    public function disableDebug() {
980 980
         $this->debug = false;
981 981
     }
982 982
 }
983 983
\ No newline at end of file
Please login to merge, or discard this patch.