Passed
Push — master ( deab0e...aa4b53 )
by Malte
01:57
created
src/Connection/Protocols/ImapProtocol.php 2 patches
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
             // First two chars are still needed for the 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
 
@@ -282,27 +282,27 @@  discard block
 block discarded – undo
282 282
     public function sendRequest($command, $tokens = [], &$tag = null) {
283 283
         if (!$tag) {
284 284
             $this->noun++;
285
-            $tag = 'TAG' . $this->noun;
285
+            $tag = 'TAG'.$this->noun;
286 286
         }
287 287
 
288
-        $line = $tag . ' ' . $command;
288
+        $line = $tag.' '.$command;
289 289
 
290 290
         foreach ($tokens as $token) {
291 291
             if (is_array($token)) {
292
-                if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) {
292
+                if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) {
293 293
                     throw new RuntimeException('failed to write - connection closed?');
294 294
                 }
295 295
                 if (!$this->assumedNextLine('+ ')) {
296 296
                     throw new RuntimeException('failed to send literal string');
297 297
                 }
298 298
                 $line = $token[1];
299
-            } else {
300
-                $line .= ' ' . $token;
299
+            }else {
300
+                $line .= ' '.$token;
301 301
             }
302 302
         }
303 303
         if ($this->debug) echo ">> ".$line."\n";
304 304
 
305
-        if (fwrite($this->stream, $line . "\r\n") === false) {
305
+        if (fwrite($this->stream, $line."\r\n") === false) {
306 306
             throw new RuntimeException('failed to write - connection closed?');
307 307
         }
308 308
     }
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
     public function escapeString($string) {
333 333
         if (func_num_args() < 2) {
334 334
             if (strpos($string, "\n") !== false) {
335
-                return ['{' . strlen($string) . '}', $string];
336
-            } else {
337
-                return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"';
335
+                return ['{'.strlen($string).'}', $string];
336
+            }else {
337
+                return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"';
338 338
             }
339 339
         }
340 340
         $result = [];
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
             }
360 360
             $result[] = $this->escapeList($v);
361 361
         }
362
-        return '(' . implode(' ', $result) . ')';
362
+        return '('.implode(' ', $result).')';
363 363
     }
364 364
 
365 365
     /**
@@ -399,12 +399,12 @@  discard block
 block discarded – undo
399 399
                     error_log("got an extra server challenge: $response");
400 400
                     // respond with an empty response.
401 401
                     $this->sendRequest('');
402
-                } else {
402
+                }else {
403 403
                     if (preg_match('/^NO /i', $response) ||
404 404
                         preg_match('/^BAD /i', $response)) {
405 405
                         error_log("got failure response: $response");
406 406
                         return false;
407
-                    } else if (preg_match("/^OK /i", $response)) {
407
+                    }else if (preg_match("/^OK /i", $response)) {
408 408
                         return true;
409 409
                     }
410 410
                 }
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
      *
438 438
      * @return bool
439 439
      */
440
-    public function connected(){
440
+    public function connected() {
441 441
         return (boolean) $this->stream;
442 442
     }
443 443
 
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
                     $result[strtolower($tokens[1])] = $tokens[0];
485 485
                     break;
486 486
                 case '[UIDVALIDITY':
487
-                    $result['uidvalidity'] = (int)$tokens[2];
487
+                    $result['uidvalidity'] = (int) $tokens[2];
488 488
                     break;
489 489
                 case '[UIDNEXT':
490
-                    $result['uidnext'] = (int)$tokens[2];
490
+                    $result['uidnext'] = (int) $tokens[2];
491 491
                     break;
492 492
                 default:
493 493
                     // ignore
@@ -541,17 +541,17 @@  discard block
 block discarded – undo
541 541
         if (is_array($from)) {
542 542
             $set = implode(',', $from);
543 543
         } elseif ($to === null) {
544
-            $set = (int)$from;
544
+            $set = (int) $from;
545 545
         } elseif ($to === INF) {
546
-            $set = (int)$from . ':*';
547
-        } else {
548
-            $set = (int)$from . ':' . (int)$to;
546
+            $set = (int) $from.':*';
547
+        }else {
548
+            $set = (int) $from.':'.(int) $to;
549 549
         }
550 550
 
551
-        $items = (array)$items;
551
+        $items = (array) $items;
552 552
         $itemList = $this->escapeList($items);
553 553
 
554
-        $this->sendRequest(($uid ? 'UID ' : '') . 'FETCH', [$set, $itemList], $tag);
554
+        $this->sendRequest(($uid ? 'UID ' : '').'FETCH', [$set, $itemList], $tag);
555 555
 
556 556
         $result = [];
557 557
         $tokens = null; // define $tokens variable before first use
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
                 $count = count($tokens[2]);
567 567
                 if ($tokens[2][$count - 2] == 'UID') {
568 568
                     $uidKey = $count - 1;
569
-                } else {
569
+                }else {
570 570
                     $uidKey = array_search('UID', $tokens[2]) + 1;
571 571
                 }
572 572
             }
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
                     $data = $tokens[2][1];
583 583
                 } elseif ($uid && $tokens[2][2] == $items[0]) {
584 584
                     $data = $tokens[2][3];
585
-                } else {
585
+                }else {
586 586
                     // maybe the server send an other field we didn't wanted
587 587
                     $count = count($tokens[2]);
588 588
                     // we start with 2, because 0 was already checked
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
                         break;
595 595
                     }
596 596
                 }
597
-            } else {
597
+            }else {
598 598
                 $data = [];
599 599
                 while (key($tokens[2]) !== null) {
600 600
                     $data[current($tokens[2])] = next($tokens[2]);
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
      * @return array
640 640
      * @throws RuntimeException
641 641
      */
642
-    public function headers($uids, $rfc = "RFC822"){
642
+    public function headers($uids, $rfc = "RFC822") {
643 643
         return $this->fetch(["$rfc.HEADER"], $uids);
644 644
     }
645 645
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
      * @return array
651 651
      * @throws RuntimeException
652 652
      */
653
-    public function flags($uids){
653
+    public function flags($uids) {
654 654
         return $this->fetch(["FLAGS"], $uids);
655 655
     }
656 656
 
@@ -734,22 +734,22 @@  discard block
 block discarded – undo
734 734
     public function store(array $flags, $from, $to = null, $mode = null, $silent = true) {
735 735
         $item = 'FLAGS';
736 736
         if ($mode == '+' || $mode == '-') {
737
-            $item = $mode . $item;
737
+            $item = $mode.$item;
738 738
         }
739 739
         if ($silent) {
740 740
             $item .= '.SILENT';
741 741
         }
742 742
 
743 743
         $flags = $this->escapeList($flags);
744
-        $set = (int)$from;
744
+        $set = (int) $from;
745 745
         if ($to !== null) {
746
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
746
+            $set .= ':'.($to == INF ? '*' : (int) $to);
747 747
         }
748 748
 
749 749
         $result = $this->requestAndResponse('STORE', [$set, $item, $flags], $silent);
750 750
 
751 751
         if ($silent) {
752
-            return (bool)$result;
752
+            return (bool) $result;
753 753
         }
754 754
 
755 755
         $tokens = $result;
@@ -799,9 +799,9 @@  discard block
 block discarded – undo
799 799
      * @throws RuntimeException
800 800
      */
801 801
     public function copyMessage($folder, $from, $to = null) {
802
-        $set = (int)$from;
802
+        $set = (int) $from;
803 803
         if ($to !== null) {
804
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
804
+            $set .= ':'.($to == INF ? '*' : (int) $to);
805 805
         }
806 806
 
807 807
         return $this->requestAndResponse('COPY', [$set, $this->escapeString($folder)], true);
@@ -818,9 +818,9 @@  discard block
 block discarded – undo
818 818
      * @throws RuntimeException
819 819
      */
820 820
     public function moveMessage($folder, $from, $to = null) {
821
-        $set = (int)$from;
821
+        $set = (int) $from;
822 822
         if ($to !== null) {
823
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
823
+            $set .= ':'.($to == INF ? '*' : (int) $to);
824 824
         }
825 825
 
826 826
         return $this->requestAndResponse('MOVE', [$set, $this->escapeString($folder)], true);
@@ -971,14 +971,14 @@  discard block
 block discarded – undo
971 971
     /**
972 972
      * Enable the debug mode
973 973
      */
974
-    public function enableDebug(){
974
+    public function enableDebug() {
975 975
         $this->debug = true;
976 976
     }
977 977
 
978 978
     /**
979 979
      * Disable the debug mode
980 980
      */
981
-    public function disableDebug(){
981
+    public function disableDebug() {
982 982
         $this->debug = false;
983 983
     }
984 984
 }
985 985
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -256,9 +256,13 @@  discard block
 block discarded – undo
256 256
             $tokens = [substr($tokens, 0, 2)];
257 257
         }
258 258
         if (is_array($lines)){
259
-            if ($this->debug) echo "<< ".json_encode($lines)."\n";
260
-        }else{
261
-            if ($this->debug) echo "<< ".$lines."\n";
259
+            if ($this->debug) {
260
+                echo "<< ".json_encode($lines)."\n";
261
+            }
262
+        } else{
263
+            if ($this->debug) {
264
+                echo "<< ".$lines."\n";
265
+            }
262 266
         }
263 267
 
264 268
         // last line has response code
@@ -300,7 +304,9 @@  discard block
 block discarded – undo
300 304
                 $line .= ' ' . $token;
301 305
             }
302 306
         }
303
-        if ($this->debug) echo ">> ".$line."\n";
307
+        if ($this->debug) {
308
+            echo ">> ".$line."\n";
309
+        }
304 310
 
305 311
         if (fwrite($this->stream, $line . "\r\n") === false) {
306 312
             throw new RuntimeException('failed to write - connection closed?');
@@ -450,7 +456,9 @@  discard block
 block discarded – undo
450 456
     public function getCapabilities() {
451 457
         $response = $this->requestAndResponse('CAPABILITY');
452 458
 
453
-        if (!$response) return [];
459
+        if (!$response) {
460
+            return [];
461
+        }
454 462
 
455 463
         $capabilities = [];
456 464
         foreach ($response as $line) {
@@ -605,9 +613,10 @@  discard block
 block discarded – undo
605 613
             // if we want only one message we can ignore everything else and just return
606 614
             if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {
607 615
                 // we still need to read all lines
608
-                while (!$this->readLine($tokens, $tag))
609
-
616
+                while (!$this->readLine($tokens, $tag)) {
617
+                
610 618
                     return $data;
619
+                }
611 620
             }
612 621
             $result[$tokens[0]] = $data;
613 622
         }
Please login to merge, or discard this patch.