Passed
Branch master (543752)
by Malte
231:16 queued 229:13
created
src/Header.php 2 patches
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      * @throws MethodNotFoundException
83 83
      */
84 84
     public function __call($method, $arguments) {
85
-        if(strtolower(substr($method, 0, 3)) === 'get') {
85
+        if (strtolower(substr($method, 0, 3)) === 'get') {
86 86
             $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3));
87 87
 
88
-            if(in_array($name, array_keys($this->attributes))) {
88
+            if (in_array($name, array_keys($this->attributes))) {
89 89
                 return $this->attributes[$name];
90 90
             }
91 91
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      * @return Attribute|mixed
112 112
      */
113 113
     public function get($name) {
114
-        if(isset($this->attributes[$name])) {
114
+        if (isset($this->attributes[$name])) {
115 115
             return $this->attributes[$name];
116 116
         }
117 117
 
@@ -127,23 +127,23 @@  discard block
 block discarded – undo
127 127
      * @return Attribute
128 128
      */
129 129
     public function set($name, $value, $strict = false) {
130
-        if(isset($this->attributes[$name]) && $strict === false) {
130
+        if (isset($this->attributes[$name]) && $strict === false) {
131 131
             if ($this->attributize) {
132 132
                 $this->attributes[$name]->add($value, true);
133
-            }else{
134
-                if(isset($this->attributes[$name])) {
133
+            }else {
134
+                if (isset($this->attributes[$name])) {
135 135
                     if (is_array($this->attributes[$name]) == false) {
136 136
                         $this->attributes[$name] = [$this->attributes[$name], $value];
137
-                    }else{
137
+                    }else {
138 138
                         $this->attributes[$name][] = $value;
139 139
                     }
140
-                }else{
140
+                }else {
141 141
                     $this->attributes[$name] = $value;
142 142
                 }
143 143
             }
144
-        }elseif($this->attributize == false){
144
+        }elseif ($this->attributize == false) {
145 145
             $this->attributes[$name] = $value;
146
-        }else{
146
+        }else {
147 147
             $this->attributes[$name] = new Attribute($name, $value);
148 148
         }
149 149
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
     public function find($pattern) {
160 160
         if (preg_match_all($pattern, $this->raw, $matches)) {
161 161
             if (isset($matches[1])) {
162
-                if(count($matches[1]) > 0) {
162
+                if (count($matches[1]) > 0) {
163 163
                     return $matches[1][0];
164 164
                 }
165 165
             }
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      *
173 173
      * @throws InvalidMessageDateException
174 174
      */
175
-    protected function parse(){
175
+    protected function parse() {
176 176
         $header = $this->rfc822_parse_headers($this->raw);
177 177
 
178 178
         $this->extractAddresses($header);
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $this->parseDate($header);
191 191
         foreach ($header as $key => $value) {
192 192
             $key = trim(rtrim(strtolower($key)));
193
-            if(!isset($this->attributes[$key])){
193
+            if (!isset($this->attributes[$key])) {
194 194
                 $this->set($key, $value);
195 195
             }
196 196
         }
@@ -206,12 +206,12 @@  discard block
 block discarded – undo
206 206
      *
207 207
      * @return object
208 208
      */
209
-    public function rfc822_parse_headers($raw_headers){
209
+    public function rfc822_parse_headers($raw_headers) {
210 210
         $headers = [];
211 211
         $imap_headers = [];
212 212
         if (extension_loaded('imap')) {
213 213
             $raw_imap_headers = (array) \imap_rfc822_parse_headers($this->raw);
214
-            foreach($raw_imap_headers as $key => $values) {
214
+            foreach ($raw_imap_headers as $key => $values) {
215 215
                 $key = str_replace("-", "_", $key);
216 216
                 $imap_headers[$key] = $values;
217 217
             }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
         $lines = explode("\r\n", $raw_headers);
221 221
         $prev_header = null;
222
-        foreach($lines as $line) {
222
+        foreach ($lines as $line) {
223 223
             if (substr($line, 0, 1) === "\n") {
224 224
                 $line = substr($line, 1);
225 225
             }
@@ -239,19 +239,19 @@  discard block
 block discarded – undo
239 239
                     }
240 240
                     if (is_array($headers[$prev_header])) {
241 241
                         $headers[$prev_header][] = $line;
242
-                    }else{
242
+                    }else {
243 243
                         $headers[$prev_header] .= $line;
244 244
                     }
245 245
                 }
246
-            }else{
246
+            }else {
247 247
                 if (($pos = strpos($line, ":")) > 0) {
248 248
                     $key = trim(rtrim(strtolower(substr($line, 0, $pos))));
249 249
                     $key = str_replace("-", "_", $key);
250 250
 
251 251
                     $value = trim(rtrim(substr($line, $pos + 1)));
252 252
                     if (isset($headers[$key])) {
253
-                        $headers[$key][]  = $value;
254
-                    }else{
253
+                        $headers[$key][] = $value;
254
+                    }else {
255 255
                         $headers[$key] = [$value];
256 256
                     }
257 257
                     $prev_header = $key;
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
             }
260 260
         }
261 261
 
262
-        foreach($headers as $key => $values) {
262
+        foreach ($headers as $key => $values) {
263 263
             if (isset($imap_headers[$key])) continue;
264 264
             $value = null;
265
-            switch($key){
265
+            switch ($key) {
266 266
                 case 'from':
267 267
                 case 'to':
268 268
                 case 'cc':
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                     break;
278 278
                 default:
279 279
                     if (is_array($values)) {
280
-                        foreach($values as $k => $v) {
280
+                        foreach ($values as $k => $v) {
281 281
                             if ($v == "") {
282 282
                                 unset($values[$k]);
283 283
                             }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
                             $value = implode(" ", $values);
290 290
                         } elseif ($available_values > 2) {
291 291
                             $value = array_values($values);
292
-                        } else {
292
+                        }else {
293 293
                             $value = "";
294 294
                         }
295 295
                     }
@@ -309,12 +309,12 @@  discard block
 block discarded – undo
309 309
      * @return array The decoded elements are returned in an array of objects, where each
310 310
      * object has two properties, charset and text.
311 311
      */
312
-    public function mime_header_decode($text){
312
+    public function mime_header_decode($text) {
313 313
         if (extension_loaded('imap')) {
314 314
             return \imap_mime_header_decode($text);
315 315
         }
316 316
         $charset = $this->getEncoding($text);
317
-        return [(object)[
317
+        return [(object) [
318 318
             "charset" => $charset,
319 319
             "text" => $this->convertEncoding($text, $charset)
320 320
         ]];
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         try {
369 369
             if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
370 370
                 return iconv($from, $to, $str);
371
-            } else {
371
+            }else {
372 372
                 if (!$from) {
373 373
                     return mb_convert_encoding($str, $to);
374 374
                 }
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             if (strstr($from, '-')) {
379 379
                 $from = str_replace('-', '', $from);
380 380
                 return $this->convertEncoding($str, $from, $to);
381
-            } else {
381
+            }else {
382 382
                 return $str;
383 383
             }
384 384
         }
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             }
400 400
         }elseif (property_exists($structure, 'charset')) {
401 401
             return EncodingAliases::get($structure->charset, $this->fallback_encoding);
402
-        }elseif (is_string($structure) === true){
402
+        }elseif (is_string($structure) === true) {
403 403
             return mb_detect_encoding($structure);
404 404
         }
405 405
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
         $decoder = $this->config['decoder']['message'];
421 421
 
422 422
         if ($value !== null) {
423
-            if($decoder === 'utf-8' && extension_loaded('imap')) {
423
+            if ($decoder === 'utf-8' && extension_loaded('imap')) {
424 424
                 $value = \imap_utf8($value);
425 425
                 if (strpos(strtolower($value), '=?utf-8?') === 0) {
426 426
                     $value = mb_decode_mimeheader($value);
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
                 if ($this->notDecoded($original_value, $value)) {
429 429
                     $decoded_value = $this->mime_header_decode($value);
430 430
                     if (count($decoded_value) > 0) {
431
-                        if(property_exists($decoded_value[0], "text")) {
431
+                        if (property_exists($decoded_value[0], "text")) {
432 432
                             $value = $decoded_value[0]->text;
433 433
                         }
434 434
                     }
435 435
                 }
436
-            }elseif($decoder === 'iconv') {
436
+            }elseif ($decoder === 'iconv') {
437 437
                 $value = iconv_mime_decode($value);
438
-            }else{
438
+            }else {
439 439
                 $value = mb_decode_mimeheader($value);
440 440
             }
441 441
 
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
      * @return array
459 459
      */
460 460
     private function decodeArray($values) {
461
-        foreach($values as $key => $value) {
461
+        foreach ($values as $key => $value) {
462 462
             $values[$key] = $this->decode($value);
463 463
         }
464 464
         return $values;
@@ -468,8 +468,8 @@  discard block
 block discarded – undo
468 468
      * Try to extract the priority from a given raw header string
469 469
      */
470 470
     private function findPriority() {
471
-        if(($priority = $this->get("x_priority")) === null) return;
472
-        switch((int)"$priority"){
471
+        if (($priority = $this->get("x_priority")) === null) return;
472
+        switch ((int) "$priority") {
473 473
             case IMAP::MESSAGE_PRIORITY_HIGHEST;
474 474
                 $priority = IMAP::MESSAGE_PRIORITY_HIGHEST;
475 475
                 break;
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
      */
502 502
     private function decodeAddresses($values) {
503 503
         $addresses = [];
504
-        foreach($values as $address) {
504
+        foreach ($values as $address) {
505 505
             $address = trim(rtrim($address));
506 506
             if (strpos($address, ",") == strlen($address) - 1) {
507 507
                 $address = substr($address, 0, -1);
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
                 '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/',
511 511
                 $address,
512 512
                 $matches
513
-            )){
513
+            )) {
514 514
                 $name = trim(rtrim($matches["name"]));
515 515
                 $email = trim(rtrim($matches["email"]));
516 516
                 list($mailbox, $host) = array_pad(explode("@", $email), 2, null);
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
      * @param object $header
530 530
      */
531 531
     private function extractAddresses($header) {
532
-        foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){
532
+        foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) {
533 533
             if (property_exists($header, $key)) {
534 534
                 $this->set($key, $this->parseAddresses($header->$key));
535 535
             }
@@ -560,10 +560,10 @@  discard block
 block discarded – undo
560 560
             }
561 561
             if (!property_exists($address, 'personal')) {
562 562
                 $address->personal = false;
563
-            } else {
563
+            }else {
564 564
                 $personalParts = $this->mime_header_decode($address->personal);
565 565
 
566
-                if(is_array($personalParts)) {
566
+                if (is_array($personalParts)) {
567 567
                     $address->personal = '';
568 568
                     foreach ($personalParts as $p) {
569 569
                         $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p));
@@ -587,23 +587,23 @@  discard block
 block discarded – undo
587 587
     /**
588 588
      * Search and extract potential header extensions
589 589
      */
590
-    private function extractHeaderExtensions(){
590
+    private function extractHeaderExtensions() {
591 591
         foreach ($this->attributes as $key => $value) {
592 592
             if (is_array($value)) {
593 593
                 $value = implode(", ", $value);
594
-            }else{
595
-                $value = (string)$value;
594
+            }else {
595
+                $value = (string) $value;
596 596
             }
597 597
             // Only parse strings and don't parse any attributes like the user-agent
598 598
             if (in_array($key, ["user_agent"]) === false) {
599
-                if (($pos = strpos($value, ";")) !== false){
599
+                if (($pos = strpos($value, ";")) !== false) {
600 600
                     $original = substr($value, 0, $pos);
601 601
                     $this->set($key, trim(rtrim($original)), true);
602 602
 
603 603
                     // Get all potential extensions
604 604
                     $extensions = explode(";", substr($value, $pos + 1));
605
-                    foreach($extensions as $extension) {
606
-                        if (($pos = strpos($extension, "=")) !== false){
605
+                    foreach ($extensions as $extension) {
606
+                        if (($pos = strpos($extension, "=")) !== false) {
607 607
                             $key = substr($extension, 0, $pos);
608 608
                             $key = trim(rtrim(strtolower($key)));
609 609
 
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
             $parsed_date = null;
647 647
             $date = $header->date;
648 648
 
649
-            if(preg_match('/\+0580/', $date)) {
649
+            if (preg_match('/\+0580/', $date)) {
650 650
                 $date = str_replace('+0580', '+0530', $date);
651 651
             }
652 652
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
                         $date = trim(array_pop($array));
670 670
                         break;
671 671
                 }
672
-                try{
672
+                try {
673 673
                     $parsed_date = Carbon::parse($date);
674 674
                 } catch (\Exception $_e) {
675 675
                     throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e);
Please login to merge, or discard this patch.
Braces   +20 added lines, -16 removed lines patch added patch discarded remove patch
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
         if(isset($this->attributes[$name]) && $strict === false) {
131 131
             if ($this->attributize) {
132 132
                 $this->attributes[$name]->add($value, true);
133
-            }else{
133
+            } else{
134 134
                 if(isset($this->attributes[$name])) {
135 135
                     if (is_array($this->attributes[$name]) == false) {
136 136
                         $this->attributes[$name] = [$this->attributes[$name], $value];
137
-                    }else{
137
+                    } else{
138 138
                         $this->attributes[$name][] = $value;
139 139
                     }
140
-                }else{
140
+                } else{
141 141
                     $this->attributes[$name] = $value;
142 142
                 }
143 143
             }
144
-        }elseif($this->attributize == false){
144
+        } elseif($this->attributize == false){
145 145
             $this->attributes[$name] = $value;
146
-        }else{
146
+        } else{
147 147
             $this->attributes[$name] = new Attribute($name, $value);
148 148
         }
149 149
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                 if ($prev_header !== null) {
231 231
                     $headers[$prev_header][] = $line;
232 232
                 }
233
-            }elseif (substr($line, 0, 1) === " ") {
233
+            } elseif (substr($line, 0, 1) === " ") {
234 234
                 $line = substr($line, 1);
235 235
                 $line = trim(rtrim($line));
236 236
                 if ($prev_header !== null) {
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
                     }
240 240
                     if (is_array($headers[$prev_header])) {
241 241
                         $headers[$prev_header][] = $line;
242
-                    }else{
242
+                    } else{
243 243
                         $headers[$prev_header] .= $line;
244 244
                     }
245 245
                 }
246
-            }else{
246
+            } else{
247 247
                 if (($pos = strpos($line, ":")) > 0) {
248 248
                     $key = trim(rtrim(strtolower(substr($line, 0, $pos))));
249 249
                     $key = str_replace("-", "_", $key);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                     $value = trim(rtrim(substr($line, $pos + 1)));
252 252
                     if (isset($headers[$key])) {
253 253
                         $headers[$key][]  = $value;
254
-                    }else{
254
+                    } else{
255 255
                         $headers[$key] = [$value];
256 256
                     }
257 257
                     $prev_header = $key;
@@ -260,7 +260,9 @@  discard block
 block discarded – undo
260 260
         }
261 261
 
262 262
         foreach($headers as $key => $values) {
263
-            if (isset($imap_headers[$key])) continue;
263
+            if (isset($imap_headers[$key])) {
264
+                continue;
265
+            }
264 266
             $value = null;
265 267
             switch($key){
266 268
                 case 'from':
@@ -397,9 +399,9 @@  discard block
 block discarded – undo
397 399
                     return EncodingAliases::get($parameter->value, $this->fallback_encoding);
398 400
                 }
399 401
             }
400
-        }elseif (property_exists($structure, 'charset')) {
402
+        } elseif (property_exists($structure, 'charset')) {
401 403
             return EncodingAliases::get($structure->charset, $this->fallback_encoding);
402
-        }elseif (is_string($structure) === true){
404
+        } elseif (is_string($structure) === true){
403 405
             return mb_detect_encoding($structure);
404 406
         }
405 407
 
@@ -433,9 +435,9 @@  discard block
 block discarded – undo
433 435
                         }
434 436
                     }
435 437
                 }
436
-            }elseif($decoder === 'iconv') {
438
+            } elseif($decoder === 'iconv') {
437 439
                 $value = iconv_mime_decode($value);
438
-            }else{
440
+            } else{
439 441
                 $value = mb_decode_mimeheader($value);
440 442
             }
441 443
 
@@ -468,7 +470,9 @@  discard block
 block discarded – undo
468 470
      * Try to extract the priority from a given raw header string
469 471
      */
470 472
     private function findPriority() {
471
-        if(($priority = $this->get("x_priority")) === null) return;
473
+        if(($priority = $this->get("x_priority")) === null) {
474
+            return;
475
+        }
472 476
         switch((int)"$priority"){
473 477
             case IMAP::MESSAGE_PRIORITY_HIGHEST;
474 478
                 $priority = IMAP::MESSAGE_PRIORITY_HIGHEST;
@@ -591,7 +595,7 @@  discard block
 block discarded – undo
591 595
         foreach ($this->attributes as $key => $value) {
592 596
             if (is_array($value)) {
593 597
                 $value = implode(", ", $value);
594
-            }else{
598
+            } else{
595 599
                 $value = (string)$value;
596 600
             }
597 601
             // Only parse strings and don't parse any attributes like the user-agent
Please login to merge, or discard this patch.
src/Address.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -44,11 +44,11 @@  discard block
 block discarded – undo
44 44
      * @param object   $object
45 45
      */
46 46
     public function __construct($object) {
47
-        if (property_exists($object, "personal")){ $this->personal = $object->personal; }
48
-        if (property_exists($object, "mailbox")){ $this->mailbox = $object->mailbox; }
49
-        if (property_exists($object, "host")){ $this->host = $object->host; }
50
-        if (property_exists($object, "mail")){ $this->mail = $object->mail; }
51
-        if (property_exists($object, "full")){ $this->full = $object->full; }
47
+        if (property_exists($object, "personal")) { $this->personal = $object->personal; }
48
+        if (property_exists($object, "mailbox")) { $this->mailbox = $object->mailbox; }
49
+        if (property_exists($object, "host")) { $this->host = $object->host; }
50
+        if (property_exists($object, "mail")) { $this->mail = $object->mail; }
51
+        if (property_exists($object, "full")) { $this->full = $object->full; }
52 52
     }
53 53
 
54 54
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *
67 67
      * @return array
68 68
      */
69
-    public function __serialize(){
69
+    public function __serialize() {
70 70
         return [
71 71
             "personal" => $this->personal,
72 72
             "mailbox" => $this->mailbox,
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      *
82 82
      * @return array
83 83
      */
84
-    public function toArray(){
84
+    public function toArray() {
85 85
         return $this->__serialize();
86 86
     }
87 87
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return string
92 92
      */
93
-    public function toString(){
93
+    public function toString() {
94 94
         return $this->__toString();
95 95
     }
96 96
 }
97 97
\ No newline at end of file
Please login to merge, or discard this patch.
src/Connection/Protocols/ImapProtocol.php 2 patches
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @throws ConnectionFailedException
85 85
      * @throws RuntimeException
86 86
      */
87
-    protected function enableTls(){
87
+    protected function enableTls() {
88 88
         $response = $this->requestAndResponse('STARTTLS');
89 89
         $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod());
90 90
         if (!$result) {
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         $stack = [];
147 147
 
148 148
         //  replace any trailing <NL> including spaces with a single space
149
-        $line = rtrim($line) . ' ';
149
+        $line = rtrim($line).' ';
150 150
         while (($pos = strpos($line, ' ')) !== false) {
151 151
             $token = substr($line, 0, $pos);
152 152
             if (!strlen($token)) {
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
                     if (strlen($token) > $chars) {
177 177
                         $line = substr($token, $chars);
178 178
                         $token = substr($token, 0, $chars);
179
-                    } else {
179
+                    }else {
180 180
                         $line .= $this->nextLine();
181 181
                     }
182 182
                     $tokens[] = $token;
183
-                    $line = trim($line) . ' ';
183
+                    $line = trim($line).' ';
184 184
                     continue;
185 185
                 }
186 186
             }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
         $line = $this->nextTaggedLine($tag); // get next tag
231 231
         if (!$dontParse) {
232 232
             $tokens = $this->decodeLine($line);
233
-        } else {
233
+        }else {
234 234
             $tokens = $line;
235 235
         }
236 236
         if ($this->debug) echo "<< ".$line."\n";
@@ -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,9 +564,9 @@  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 if ($tokens[2][0] == 'UID') {
567
+                }else if ($tokens[2][0] == 'UID') {
568 568
                     $uidKey = 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]);
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
             }
612 612
             if ($uid) {
613 613
                 $result[$tokens[2][$uidKey]] = $data;
614
-            }else{
614
+            }else {
615 615
                 $result[$tokens[0]] = $data;
616 616
             }
617 617
         }
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
      * @return array
646 646
      * @throws RuntimeException
647 647
      */
648
-    public function headers($uids, $rfc = "RFC822", $uid = false){
648
+    public function headers($uids, $rfc = "RFC822", $uid = false) {
649 649
         return $this->fetch(["$rfc.HEADER"], $uids, null, $uid);
650 650
     }
651 651
 
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
      * @return array
658 658
      * @throws RuntimeException
659 659
      */
660
-    public function flags($uids, $uid = false){
660
+    public function flags($uids, $uid = false) {
661 661
         return $this->fetch(["FLAGS"], $uids, null, $uid);
662 662
     }
663 663
 
@@ -742,23 +742,23 @@  discard block
 block discarded – undo
742 742
     public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = false) {
743 743
         $item = 'FLAGS';
744 744
         if ($mode == '+' || $mode == '-') {
745
-            $item = $mode . $item;
745
+            $item = $mode.$item;
746 746
         }
747 747
         if ($silent) {
748 748
             $item .= '.SILENT';
749 749
         }
750 750
 
751 751
         $flags = $this->escapeList($flags);
752
-        $set = (int)$from;
752
+        $set = (int) $from;
753 753
         if ($to !== null) {
754
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
754
+            $set .= ':'.($to == INF ? '*' : (int) $to);
755 755
         }
756 756
 
757 757
         $command = ($uid ? "UID " : "")."STORE";
758 758
         $result = $this->requestAndResponse($command, [$set, $item, $flags], $silent);
759 759
 
760 760
         if ($silent) {
761
-            return (bool)$result;
761
+            return (bool) $result;
762 762
         }
763 763
 
764 764
         $tokens = $result;
@@ -809,9 +809,9 @@  discard block
 block discarded – undo
809 809
      * @throws RuntimeException
810 810
      */
811 811
     public function copyMessage($folder, $from, $to = null, $uid = false) {
812
-        $set = (int)$from;
812
+        $set = (int) $from;
813 813
         if ($to !== null) {
814
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
814
+            $set .= ':'.($to == INF ? '*' : (int) $to);
815 815
         }
816 816
         $command = ($uid ? "UID " : "")."COPY";
817 817
 
@@ -830,9 +830,9 @@  discard block
 block discarded – undo
830 830
      * @throws RuntimeException
831 831
      */
832 832
     public function moveMessage($folder, $from, $to = null, $uid = false) {
833
-        $set = (int)$from;
833
+        $set = (int) $from;
834 834
         if ($to !== null) {
835
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
835
+            $set .= ':'.($to == INF ? '*' : (int) $to);
836 836
         }
837 837
         $command = ($uid ? "UID " : "")."MOVE";
838 838
 
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
         $ids = [];
1003 1003
         foreach ($uids as $msgn => $v) {
1004 1004
             $id = $uid ? $v : $msgn;
1005
-            if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){
1005
+            if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) {
1006 1006
                 $ids[] = $id;
1007 1007
             }
1008 1008
         }
@@ -1016,14 +1016,14 @@  discard block
 block discarded – undo
1016 1016
     /**
1017 1017
      * Enable the debug mode
1018 1018
      */
1019
-    public function enableDebug(){
1019
+    public function enableDebug() {
1020 1020
         $this->debug = true;
1021 1021
     }
1022 1022
 
1023 1023
     /**
1024 1024
      * Disable the debug mode
1025 1025
      */
1026
-    public function disableDebug(){
1026
+    public function disableDebug() {
1027 1027
         $this->debug = false;
1028 1028
     }
1029 1029
 }
1030 1030
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +13 added lines, -6 removed lines patch added patch discarded remove patch
@@ -233,7 +233,9 @@  discard block
 block discarded – undo
233 233
         } else {
234 234
             $tokens = $line;
235 235
         }
236
-        if ($this->debug) echo "<< ".$line."\n";
236
+        if ($this->debug) {
237
+            echo "<< ".$line."\n";
238
+        }
237 239
 
238 240
         // if tag is wanted tag we might be at the end of a multiline response
239 241
         return $tag == $wantedTag;
@@ -298,7 +300,9 @@  discard block
 block discarded – undo
298 300
                 $line .= ' ' . $token;
299 301
             }
300 302
         }
301
-        if ($this->debug) echo ">> ".$line."\n";
303
+        if ($this->debug) {
304
+            echo ">> ".$line."\n";
305
+        }
302 306
 
303 307
         if (fwrite($this->stream, $line . "\r\n") === false) {
304 308
             throw new RuntimeException('failed to write - connection closed?');
@@ -448,7 +452,9 @@  discard block
 block discarded – undo
448 452
     public function getCapabilities() {
449 453
         $response = $this->requestAndResponse('CAPABILITY');
450 454
 
451
-        if (!$response) return [];
455
+        if (!$response) {
456
+            return [];
457
+        }
452 458
 
453 459
         $capabilities = [];
454 460
         foreach ($response as $line) {
@@ -605,13 +611,14 @@  discard block
 block discarded – undo
605 611
             // if we want only one message we can ignore everything else and just return
606 612
             if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {
607 613
                 // we still need to read all lines
608
-                while (!$this->readLine($tokens, $tag))
609
-
614
+                while (!$this->readLine($tokens, $tag)) {
615
+                
610 616
                     return $data;
617
+                }
611 618
             }
612 619
             if ($uid) {
613 620
                 $result[$tokens[2][$uidKey]] = $data;
614
-            }else{
621
+            } else{
615 622
                 $result[$tokens[0]] = $data;
616 623
             }
617 624
         }
Please login to merge, or discard this patch.