Passed
Push — master ( 17f7bb...ab922f )
by Malte
02:36
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
 
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         if ($value !== null) {
433 433
             $is_utf8_base = $this->is_uft8($value);
434 434
 
435
-            if($decoder === 'utf-8' && extension_loaded('imap')) {
435
+            if ($decoder === 'utf-8' && extension_loaded('imap')) {
436 436
                 $value = \imap_utf8($value);
437 437
                 $is_utf8_base = $this->is_uft8($value);
438 438
                 if ($is_utf8_base) {
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
                 if ($this->notDecoded($original_value, $value)) {
442 442
                     $decoded_value = $this->mime_header_decode($value);
443 443
                     if (count($decoded_value) > 0) {
444
-                        if(property_exists($decoded_value[0], "text")) {
444
+                        if (property_exists($decoded_value[0], "text")) {
445 445
                             $value = $decoded_value[0]->text;
446 446
                         }
447 447
                     }
448 448
                 }
449
-            }elseif($decoder === 'iconv' && $is_utf8_base) {
449
+            }elseif ($decoder === 'iconv' && $is_utf8_base) {
450 450
                 $value = iconv_mime_decode($value);
451
-            }elseif($is_utf8_base){
451
+            }elseif ($is_utf8_base) {
452 452
                 $value = mb_decode_mimeheader($value);
453 453
             }
454 454
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
      * @return array
472 472
      */
473 473
     private function decodeArray($values) {
474
-        foreach($values as $key => $value) {
474
+        foreach ($values as $key => $value) {
475 475
             $values[$key] = $this->decode($value);
476 476
         }
477 477
         return $values;
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
      * Try to extract the priority from a given raw header string
482 482
      */
483 483
     private function findPriority() {
484
-        if(($priority = $this->get("x_priority")) === null) return;
485
-        switch((int)"$priority"){
484
+        if (($priority = $this->get("x_priority")) === null) return;
485
+        switch ((int) "$priority") {
486 486
             case IMAP::MESSAGE_PRIORITY_HIGHEST;
487 487
                 $priority = IMAP::MESSAGE_PRIORITY_HIGHEST;
488 488
                 break;
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
      */
515 515
     private function decodeAddresses($values) {
516 516
         $addresses = [];
517
-        foreach($values as $address) {
517
+        foreach ($values as $address) {
518 518
             $address = trim(rtrim($address));
519 519
             if (strpos($address, ",") == strlen($address) - 1) {
520 520
                 $address = substr($address, 0, -1);
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
                 '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/',
524 524
                 $address,
525 525
                 $matches
526
-            )){
526
+            )) {
527 527
                 $name = trim(rtrim($matches["name"]));
528 528
                 $email = trim(rtrim($matches["email"]));
529 529
                 list($mailbox, $host) = array_pad(explode("@", $email), 2, null);
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
      * @param object $header
543 543
      */
544 544
     private function extractAddresses($header) {
545
-        foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){
545
+        foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) {
546 546
             if (property_exists($header, $key)) {
547 547
                 $this->set($key, $this->parseAddresses($header->$key));
548 548
             }
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
             }
574 574
             if (!property_exists($address, 'personal')) {
575 575
                 $address->personal = false;
576
-            } else {
576
+            }else {
577 577
                 $personalParts = $this->mime_header_decode($address->personal);
578 578
 
579
-                if(is_array($personalParts)) {
579
+                if (is_array($personalParts)) {
580 580
                     $address->personal = '';
581 581
                     foreach ($personalParts as $p) {
582 582
                         $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p));
@@ -600,23 +600,23 @@  discard block
 block discarded – undo
600 600
     /**
601 601
      * Search and extract potential header extensions
602 602
      */
603
-    private function extractHeaderExtensions(){
603
+    private function extractHeaderExtensions() {
604 604
         foreach ($this->attributes as $key => $value) {
605 605
             if (is_array($value)) {
606 606
                 $value = implode(", ", $value);
607
-            }else{
608
-                $value = (string)$value;
607
+            }else {
608
+                $value = (string) $value;
609 609
             }
610 610
             // Only parse strings and don't parse any attributes like the user-agent
611 611
             if (in_array($key, ["user_agent"]) === false) {
612
-                if (($pos = strpos($value, ";")) !== false){
612
+                if (($pos = strpos($value, ";")) !== false) {
613 613
                     $original = substr($value, 0, $pos);
614 614
                     $this->set($key, trim(rtrim($original)), true);
615 615
 
616 616
                     // Get all potential extensions
617 617
                     $extensions = explode(";", substr($value, $pos + 1));
618
-                    foreach($extensions as $extension) {
619
-                        if (($pos = strpos($extension, "=")) !== false){
618
+                    foreach ($extensions as $extension) {
619
+                        if (($pos = strpos($extension, "=")) !== false) {
620 620
                             $key = substr($extension, 0, $pos);
621 621
                             $key = trim(rtrim(strtolower($key)));
622 622
 
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
             $parsed_date = null;
660 660
             $date = $header->date;
661 661
 
662
-            if(preg_match('/\+0580/', $date)) {
662
+            if (preg_match('/\+0580/', $date)) {
663 663
                 $date = str_replace('+0580', '+0530', $date);
664 664
             }
665 665
 
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                         $date = trim(array_pop($array));
683 683
                         break;
684 684
                 }
685
-                try{
685
+                try {
686 686
                     $parsed_date = Carbon::parse($date);
687 687
                 } catch (\Exception $_e) {
688 688
                     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
 
@@ -446,9 +448,9 @@  discard block
 block discarded – undo
446 448
                         }
447 449
                     }
448 450
                 }
449
-            }elseif($decoder === 'iconv' && $is_utf8_base) {
451
+            } elseif($decoder === 'iconv' && $is_utf8_base) {
450 452
                 $value = iconv_mime_decode($value);
451
-            }elseif($is_utf8_base){
453
+            } elseif($is_utf8_base){
452 454
                 $value = mb_decode_mimeheader($value);
453 455
             }
454 456
 
@@ -481,7 +483,9 @@  discard block
 block discarded – undo
481 483
      * Try to extract the priority from a given raw header string
482 484
      */
483 485
     private function findPriority() {
484
-        if(($priority = $this->get("x_priority")) === null) return;
486
+        if(($priority = $this->get("x_priority")) === null) {
487
+            return;
488
+        }
485 489
         switch((int)"$priority"){
486 490
             case IMAP::MESSAGE_PRIORITY_HIGHEST;
487 491
                 $priority = IMAP::MESSAGE_PRIORITY_HIGHEST;
@@ -604,7 +608,7 @@  discard block
 block discarded – undo
604 608
         foreach ($this->attributes as $key => $value) {
605 609
             if (is_array($value)) {
606 610
                 $value = implode(", ", $value);
607
-            }else{
611
+            } else{
608 612
                 $value = (string)$value;
609 613
             }
610 614
             // Only parse strings and don't parse any attributes like the user-agent
Please login to merge, or discard this patch.
src/Message.php 2 patches
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_flags = false, $sequence = null) {
203 203
 
204 204
         $default_mask = $client->getDefaultMessageMask();
205
-        if($default_mask != null) {
205
+        if ($default_mask != null) {
206 206
             $this->mask = $default_mask;
207 207
         }
208 208
         $this->events["message"] = $client->getDefaultEvents("message");
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
      * @throws MessageFlagException
262 262
      * @throws Exceptions\RuntimeException
263 263
      */
264
-    public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null){
264
+    public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null) {
265 265
         $reflection = new \ReflectionClass(self::class);
266 266
         /** @var self $instance */
267 267
         $instance = $reflection->newInstanceWithoutConstructor();
268 268
 
269 269
         $default_mask = $client->getDefaultMessageMask();
270
-        if($default_mask != null) {
270
+        if ($default_mask != null) {
271 271
             $instance->setMask($default_mask);
272 272
         }
273 273
         $instance->setEvents([
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
      * @throws MethodNotFoundException
303 303
      */
304 304
     public function __call($method, $arguments) {
305
-        if(strtolower(substr($method, 0, 3)) === 'get') {
305
+        if (strtolower(substr($method, 0, 3)) === 'get') {
306 306
             $name = Str::snake(substr($method, 3));
307 307
             return $this->get($name);
308 308
         }elseif (strtolower(substr($method, 0, 3)) === 'set') {
309 309
             $name = Str::snake(substr($method, 3));
310 310
 
311
-            if(in_array($name, array_keys($this->attributes))) {
311
+            if (in_array($name, array_keys($this->attributes))) {
312 312
                 return $this->__set($name, array_pop($arguments));
313 313
             }
314 314
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      * @return mixed|null
348 348
      */
349 349
     public function get($name) {
350
-        if(isset($this->attributes[$name])) {
350
+        if (isset($this->attributes[$name])) {
351 351
             return $this->attributes[$name];
352 352
         }
353 353
 
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
      *
422 422
      * @throws InvalidMessageDateException
423 423
      */
424
-    public function parseRawHeader($raw_header){
424
+    public function parseRawHeader($raw_header) {
425 425
         $this->header = new Header($raw_header);
426 426
     }
427 427
 
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
     public function parseRawFlags($raw_flags) {
433 433
         $this->flags = FlagCollection::make([]);
434 434
 
435
-        foreach($raw_flags as $flag) {
436
-            if (strpos($flag, "\\") === 0){
435
+        foreach ($raw_flags as $flag) {
436
+            if (strpos($flag, "\\") === 0) {
437 437
                 $flag = substr($flag, 1);
438 438
             }
439 439
             $flag_key = strtolower($flag);
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @throws MessageFlagException
507 507
      * @throws Exceptions\RuntimeException
508 508
      */
509
-    public function peek(){
509
+    public function peek() {
510 510
         if ($this->fetch_options == IMAP::FT_PEEK) {
511 511
             if ($this->getFlags()->get("seen") == null) {
512 512
                 $this->unsetFlag("Seen");
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
     private function fetchPart(Part $part) {
556 556
         if ($part->isAttachment()) {
557 557
             $this->fetchAttachment($part);
558
-        }else{
558
+        }else {
559 559
             $encoding = $this->getEncoding($part);
560 560
 
561 561
             $content = $this->decodeString($part->content, $part->encoding);
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 
581 581
             if (isset($this->bodies[$subtype])) {
582 582
                 $this->bodies[$subtype] .= "\n".$content;
583
-            }else{
583
+            }else {
584 584
                 $this->bodies[$subtype] = $content;
585 585
             }
586 586
         }
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
         if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) {
597 597
             if ($oAttachment->getId() !== null) {
598 598
                 $this->attachments->put($oAttachment->getId(), $oAttachment);
599
-            } else {
599
+            }else {
600 600
                 $this->attachments->push($oAttachment);
601 601
             }
602 602
         }
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 
731 731
         if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
732 732
             return @iconv($from, $to.'//IGNORE', $str);
733
-        } else {
733
+        }else {
734 734
             if (!$from) {
735 735
                 return mb_convert_encoding($str, $to);
736 736
             }
@@ -751,9 +751,9 @@  discard block
 block discarded – undo
751 751
                     return EncodingAliases::get($parameter->value);
752 752
                 }
753 753
             }
754
-        }elseif (property_exists($structure, 'charset')){
754
+        }elseif (property_exists($structure, 'charset')) {
755 755
             return EncodingAliases::get($structure->charset);
756
-        }elseif (is_string($structure) === true){
756
+        }elseif (is_string($structure) === true) {
757 757
             return mb_detect_encoding($structure);
758 758
         }
759 759
 
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
      * @throws Exceptions\FolderFetchingException
769 769
      * @throws Exceptions\RuntimeException
770 770
      */
771
-    public function getFolder(){
771
+    public function getFolder() {
772 772
         return $this->client->getFolder($this->folder_path);
773 773
     }
774 774
 
@@ -784,13 +784,13 @@  discard block
 block discarded – undo
784 784
      * @throws Exceptions\GetMessagesFailedException
785 785
      * @throws Exceptions\RuntimeException
786 786
      */
787
-    public function thread($sent_folder = null, &$thread = null, $folder = null){
787
+    public function thread($sent_folder = null, &$thread = null, $folder = null) {
788 788
         $thread = $thread ? $thread : MessageCollection::make([]);
789
-        $folder = $folder ? $folder :  $this->getFolder();
789
+        $folder = $folder ? $folder : $this->getFolder();
790 790
         $sent_folder = $sent_folder ? $sent_folder : $this->client->getFolder(ClientManager::get("options.common_folders.sent", "INBOX/Sent"));
791 791
 
792 792
         /** @var Message $message */
793
-        foreach($thread as $message) {
793
+        foreach ($thread as $message) {
794 794
             if ($message->message_id == $this->message_id) {
795 795
                 return $thread;
796 796
             }
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         $this->fetchThreadByInReplyTo($thread, $this->message_id, $sent_folder, $folder, $sent_folder);
802 802
 
803 803
         if (is_array($this->in_reply_to)) {
804
-            foreach($this->in_reply_to as $in_reply_to) {
804
+            foreach ($this->in_reply_to as $in_reply_to) {
805 805
                 $this->fetchThreadByMessageId($thread, $in_reply_to, $folder, $folder, $sent_folder);
806 806
                 $this->fetchThreadByMessageId($thread, $in_reply_to, $sent_folder, $folder, $sent_folder);
807 807
             }
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
      * @throws Exceptions\GetMessagesFailedException
823 823
      * @throws Exceptions\RuntimeException
824 824
      */
825
-    protected function fetchThreadByInReplyTo(&$thread, $in_reply_to, $primary_folder, $secondary_folder, $sent_folder){
825
+    protected function fetchThreadByInReplyTo(&$thread, $in_reply_to, $primary_folder, $secondary_folder, $sent_folder) {
826 826
         $primary_folder->query()->inReplyTo($in_reply_to)
827 827
         ->setFetchBody($this->getFetchBodyOption())
828 828
         ->leaveUnread()->get()->each(function($message) use(&$thread, $secondary_folder, $sent_folder){
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
      * @throws Exceptions\GetMessagesFailedException
844 844
      * @throws Exceptions\RuntimeException
845 845
      */
846
-    protected function fetchThreadByMessageId(&$thread, $message_id, $primary_folder, $secondary_folder, $sent_folder){
846
+    protected function fetchThreadByMessageId(&$thread, $message_id, $primary_folder, $secondary_folder, $sent_folder) {
847 847
         $primary_folder->query()->messageId($message_id)
848 848
         ->setFetchBody($this->getFetchBodyOption())
849 849
         ->leaveUnread()->get()->each(function($message) use(&$thread, $secondary_folder, $sent_folder){
@@ -936,14 +936,14 @@  discard block
 block discarded – undo
936 936
      * @throws MessageFlagException
937 937
      * @throws MessageHeaderFetchingException
938 938
      */
939
-    protected function fetchNewMail($folder, $next_uid, $event, $expunge){
940
-        if($expunge) $this->client->expunge();
939
+    protected function fetchNewMail($folder, $next_uid, $event, $expunge) {
940
+        if ($expunge) $this->client->expunge();
941 941
 
942 942
         $this->client->openFolder($folder->path);
943 943
 
944 944
         if ($this->sequence === IMAP::ST_UID) {
945 945
             $sequence_id = $next_uid;
946
-        }else{
946
+        }else {
947 947
             $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
948 948
         }
949 949
 
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
      */
967 967
     public function delete($expunge = true) {
968 968
         $status = $this->setFlag("Deleted");
969
-        if($expunge) $this->client->expunge();
969
+        if ($expunge) $this->client->expunge();
970 970
 
971 971
         $event = $this->getEvent("message", "deleted");
972 972
         $event::dispatch($this);
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
      */
987 987
     public function restore($expunge = true) {
988 988
         $status = $this->unsetFlag("Deleted");
989
-        if($expunge) $this->client->expunge();
989
+        if ($expunge) $this->client->expunge();
990 990
 
991 991
         $event = $this->getEvent("message", "restored");
992 992
         $event::dispatch($this);
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
      *
1092 1092
      * @return AttachmentCollection
1093 1093
      */
1094
-    public function attachments(){
1094
+    public function attachments() {
1095 1095
         return $this->getAttachments();
1096 1096
     }
1097 1097
 
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
      *
1190 1190
      * @return FlagCollection
1191 1191
      */
1192
-    public function flags(){
1192
+    public function flags() {
1193 1193
         return $this->getFlags();
1194 1194
     }
1195 1195
 
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
      *
1199 1199
      * @return Structure|null
1200 1200
      */
1201
-    public function getStructure(){
1201
+    public function getStructure() {
1202 1202
         return $this->structure;
1203 1203
     }
1204 1204
 
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
      *
1225 1225
      * @return array
1226 1226
      */
1227
-    public function getAttributes(){
1227
+    public function getAttributes() {
1228 1228
         return array_merge($this->attributes, $this->header->getAttributes());
1229 1229
     }
1230 1230
 
@@ -1234,8 +1234,8 @@  discard block
 block discarded – undo
1234 1234
      *
1235 1235
      * @return $this
1236 1236
      */
1237
-    public function setMask($mask){
1238
-        if(class_exists($mask)){
1237
+    public function setMask($mask) {
1238
+        if (class_exists($mask)) {
1239 1239
             $this->mask = $mask;
1240 1240
         }
1241 1241
 
@@ -1247,7 +1247,7 @@  discard block
 block discarded – undo
1247 1247
      *
1248 1248
      * @return string
1249 1249
      */
1250
-    public function getMask(){
1250
+    public function getMask() {
1251 1251
         return $this->mask;
1252 1252
     }
1253 1253
 
@@ -1258,9 +1258,9 @@  discard block
 block discarded – undo
1258 1258
      * @return mixed
1259 1259
      * @throws MaskNotFoundException
1260 1260
      */
1261
-    public function mask($mask = null){
1261
+    public function mask($mask = null) {
1262 1262
         $mask = $mask !== null ? $mask : $this->mask;
1263
-        if(class_exists($mask)){
1263
+        if (class_exists($mask)) {
1264 1264
             return new $mask($this);
1265 1265
         }
1266 1266
 
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
      *
1274 1274
      * @return $this
1275 1275
      */
1276
-    public function setFolderPath($folder_path){
1276
+    public function setFolderPath($folder_path) {
1277 1277
         $this->folder_path = $folder_path;
1278 1278
 
1279 1279
         return $this;
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
      *
1286 1286
      * @return $this
1287 1287
      */
1288
-    public function setConfig($config){
1288
+    public function setConfig($config) {
1289 1289
         $this->config = $config;
1290 1290
 
1291 1291
         return $this;
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
      *
1298 1298
      * @return $this
1299 1299
      */
1300
-    public function setAvailableFlags($available_flags){
1300
+    public function setAvailableFlags($available_flags) {
1301 1301
         $this->available_flags = $available_flags;
1302 1302
 
1303 1303
         return $this;
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
      *
1310 1310
      * @return $this
1311 1311
      */
1312
-    public function setAttachments($attachments){
1312
+    public function setAttachments($attachments) {
1313 1313
         $this->attachments = $attachments;
1314 1314
 
1315 1315
         return $this;
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
      *
1322 1322
      * @return $this
1323 1323
      */
1324
-    public function setFlags($flags){
1324
+    public function setFlags($flags) {
1325 1325
         $this->flags = $flags;
1326 1326
 
1327 1327
         return $this;
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
      * @throws Exceptions\RuntimeException
1336 1336
      * @throws Exceptions\ConnectionFailedException
1337 1337
      */
1338
-    public function setClient($client){
1338
+    public function setClient($client) {
1339 1339
         $this->client = $client;
1340 1340
         $this->client->openFolder($this->folder_path);
1341 1341
 
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
      * @throws Exceptions\RuntimeException
1351 1351
      * @return $this
1352 1352
      */
1353
-    public function setUid($uid){
1353
+    public function setUid($uid) {
1354 1354
         $this->uid = $uid;
1355 1355
         $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
1356 1356
         $this->msglist = null;
@@ -1367,7 +1367,7 @@  discard block
 block discarded – undo
1367 1367
      * @throws Exceptions\RuntimeException
1368 1368
      * @return $this
1369 1369
      */
1370
-    public function setMsgn($msgn, $msglist = null){
1370
+    public function setMsgn($msgn, $msglist = null) {
1371 1371
         $this->msgn = $msgn;
1372 1372
         $this->msglist = $msglist;
1373 1373
         $this->uid = $this->client->getConnection()->getUid($this->msgn);
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
      *
1381 1381
      * @return int
1382 1382
      */
1383
-    public function getSequence(){
1383
+    public function getSequence() {
1384 1384
         return $this->sequence;
1385 1385
     }
1386 1386
 
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
      *
1390 1390
      * @return int
1391 1391
      */
1392
-    public function getSequenceId(){
1392
+    public function getSequenceId() {
1393 1393
         return $this->sequence === IMAP::ST_UID ? $this->uid : $this->msgn;
1394 1394
     }
1395 1395
 
@@ -1401,11 +1401,11 @@  discard block
 block discarded – undo
1401 1401
      * @throws Exceptions\ConnectionFailedException
1402 1402
      * @throws Exceptions\RuntimeException
1403 1403
      */
1404
-    public function setSequenceId($uid, $msglist = null){
1404
+    public function setSequenceId($uid, $msglist = null) {
1405 1405
         if ($this->getSequence() === IMAP::ST_UID) {
1406 1406
             $this->setUid($uid);
1407 1407
             $this->setMsglist($msglist);
1408
-        }else{
1408
+        }else {
1409 1409
             $this->setMsgn($uid, $msglist);
1410 1410
         }
1411 1411
     }
Please login to merge, or discard this patch.
Braces   +17 added lines, -11 removed lines patch added patch discarded remove patch
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
         if(strtolower(substr($method, 0, 3)) === 'get') {
306 306
             $name = Str::snake(substr($method, 3));
307 307
             return $this->get($name);
308
-        }elseif (strtolower(substr($method, 0, 3)) === 'set') {
308
+        } elseif (strtolower(substr($method, 0, 3)) === 'set') {
309 309
             $name = Str::snake(substr($method, 3));
310 310
 
311 311
             if(in_array($name, array_keys($this->attributes))) {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
             if ($this->getFlags()->get("seen") == null) {
512 512
                 $this->unsetFlag("Seen");
513 513
             }
514
-        }elseif ($this->getFlags()->get("seen") != null) {
514
+        } elseif ($this->getFlags()->get("seen") != null) {
515 515
             $this->setFlag("Seen");
516 516
         }
517 517
     }
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
     private function fetchPart(Part $part) {
556 556
         if ($part->isAttachment()) {
557 557
             $this->fetchAttachment($part);
558
-        }else{
558
+        } else{
559 559
             $encoding = $this->getEncoding($part);
560 560
 
561 561
             $content = $this->decodeString($part->content, $part->encoding);
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 
581 581
             if (isset($this->bodies[$subtype])) {
582 582
                 $this->bodies[$subtype] .= "\n".$content;
583
-            }else{
583
+            } else{
584 584
                 $this->bodies[$subtype] = $content;
585 585
             }
586 586
         }
@@ -751,9 +751,9 @@  discard block
 block discarded – undo
751 751
                     return EncodingAliases::get($parameter->value);
752 752
                 }
753 753
             }
754
-        }elseif (property_exists($structure, 'charset')){
754
+        } elseif (property_exists($structure, 'charset')){
755 755
             return EncodingAliases::get($structure->charset);
756
-        }elseif (is_string($structure) === true){
756
+        } elseif (is_string($structure) === true){
757 757
             return mb_detect_encoding($structure);
758 758
         }
759 759
 
@@ -937,13 +937,15 @@  discard block
 block discarded – undo
937 937
      * @throws MessageHeaderFetchingException
938 938
      */
939 939
     protected function fetchNewMail($folder, $next_uid, $event, $expunge){
940
-        if($expunge) $this->client->expunge();
940
+        if($expunge) {
941
+            $this->client->expunge();
942
+        }
941 943
 
942 944
         $this->client->openFolder($folder->path);
943 945
 
944 946
         if ($this->sequence === IMAP::ST_UID) {
945 947
             $sequence_id = $next_uid;
946
-        }else{
948
+        } else{
947 949
             $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
948 950
         }
949 951
 
@@ -966,7 +968,9 @@  discard block
 block discarded – undo
966 968
      */
967 969
     public function delete($expunge = true) {
968 970
         $status = $this->setFlag("Deleted");
969
-        if($expunge) $this->client->expunge();
971
+        if($expunge) {
972
+            $this->client->expunge();
973
+        }
970 974
 
971 975
         $event = $this->getEvent("message", "deleted");
972 976
         $event::dispatch($this);
@@ -986,7 +990,9 @@  discard block
 block discarded – undo
986 990
      */
987 991
     public function restore($expunge = true) {
988 992
         $status = $this->unsetFlag("Deleted");
989
-        if($expunge) $this->client->expunge();
993
+        if($expunge) {
994
+            $this->client->expunge();
995
+        }
990 996
 
991 997
         $event = $this->getEvent("message", "restored");
992 998
         $event::dispatch($this);
@@ -1405,7 +1411,7 @@  discard block
 block discarded – undo
1405 1411
         if ($this->getSequence() === IMAP::ST_UID) {
1406 1412
             $this->setUid($uid);
1407 1413
             $this->setMsglist($msglist);
1408
-        }else{
1414
+        } else{
1409 1415
             $this->setMsgn($uid, $msglist);
1410 1416
         }
1411 1417
     }
Please login to merge, or discard this patch.
src/Structure.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @throws MessageContentFetchingException
78 78
      * @throws InvalidMessageDateException
79 79
      */
80
-    protected function parse(){
80
+    protected function parse() {
81 81
         $this->findContentType();
82 82
         $this->parts = $this->find_parts();
83 83
     }
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
     /**
86 86
      * Determine the message content type
87 87
      */
88
-    public function findContentType(){
88
+    public function findContentType() {
89 89
 
90 90
         $content_type = $this->header->get("content_type");
91 91
         $content_type = (is_array($content_type)) ? implode(' ', $content_type) : $content_type;
92
-        if(stripos($content_type, 'multipart') === 0) {
92
+        if (stripos($content_type, 'multipart') === 0) {
93 93
             $this->type = IMAP::MESSAGE_TYPE_MULTIPART;
94
-        }else{
94
+        }else {
95 95
             $this->type = IMAP::MESSAGE_TYPE_TEXT;
96 96
         }
97 97
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      *
102 102
      * @return string|null
103 103
      */
104
-    public function getBoundary(){
104
+    public function getBoundary() {
105 105
         $boundary = $this->header->find("/boundary\=(.*)/i");
106 106
 
107 107
         if ($boundary === null) {
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
      * @throws MessageContentFetchingException
129 129
      * @throws InvalidMessageDateException
130 130
      */
131
-    public function find_parts(){
132
-        if($this->type === IMAP::MESSAGE_TYPE_MULTIPART) {
133
-            if (($boundary = $this->getBoundary()) === null)  {
131
+    public function find_parts() {
132
+        if ($this->type === IMAP::MESSAGE_TYPE_MULTIPART) {
133
+            if (($boundary = $this->getBoundary()) === null) {
134 134
                 throw new MessageContentFetchingException("no content found", 0);
135 135
             }
136 136
 
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
             ];
140 140
 
141 141
             if (preg_match("/boundary\=\"?(.*)\"?/", $this->raw, $match) == 1) {
142
-                if(is_array($match[1])){
143
-                    foreach($match[1] as $matched){
142
+                if (is_array($match[1])) {
143
+                    foreach ($match[1] as $matched) {
144 144
                         $boundaries[] = $this->clearBoundaryString($matched);
145 145
                     }
146
-                }else{
147
-                    if(!empty($match[1])) {
146
+                }else {
147
+                    if (!empty($match[1])) {
148 148
                         $boundaries[] = $this->clearBoundaryString($match[1]);
149 149
                     }
150 150
                 }
151 151
             }
152 152
 
153
-            $raw_parts = explode( $boundaries[0], str_replace($boundaries, $boundaries[0], $this->raw) );
153
+            $raw_parts = explode($boundaries[0], str_replace($boundaries, $boundaries[0], $this->raw));
154 154
             $parts = [];
155 155
             $part_number = 0;
156
-            foreach($raw_parts as $part) {
156
+            foreach ($raw_parts as $part) {
157 157
                 $part = trim(rtrim($part));
158 158
                 if ($part !== "--") {
159 159
                     $parts[] = new Part($part, null, $part_number);
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $content_type = (is_array($content_type)) ? implode(' ', $content_type) : $content_type;
92 92
         if(stripos($content_type, 'multipart') === 0) {
93 93
             $this->type = IMAP::MESSAGE_TYPE_MULTIPART;
94
-        }else{
94
+        } else{
95 95
             $this->type = IMAP::MESSAGE_TYPE_TEXT;
96 96
         }
97 97
     }
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                     foreach($match[1] as $matched){
144 144
                         $boundaries[] = $this->clearBoundaryString($matched);
145 145
                     }
146
-                }else{
146
+                } else{
147 147
                     if(!empty($match[1])) {
148 148
                         $boundaries[] = $this->clearBoundaryString($match[1]);
149 149
                     }
Please login to merge, or discard this patch.