Passed
Push — master ( 5127af...662963 )
by Malte
02:15
created
src/Header.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
      * @throws MethodNotFoundException
74 74
      */
75 75
     public function __call($method, $arguments) {
76
-        if(strtolower(substr($method, 0, 3)) === 'get') {
76
+        if (strtolower(substr($method, 0, 3)) === 'get') {
77 77
             $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3));
78 78
 
79
-            if(in_array($name, array_keys($this->attributes))) {
79
+            if (in_array($name, array_keys($this->attributes))) {
80 80
                 return $this->attributes[$name];
81 81
             }
82 82
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @return mixed|null
103 103
      */
104 104
     public function get($name) {
105
-        if(isset($this->attributes[$name])) {
105
+        if (isset($this->attributes[$name])) {
106 106
             return $this->attributes[$name];
107 107
         }
108 108
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     public function find($pattern) {
119 119
         if (preg_match_all($pattern, $this->raw, $matches)) {
120 120
             if (isset($matches[1])) {
121
-                if(count($matches[1]) > 0) {
121
+                if (count($matches[1]) > 0) {
122 122
                     return $matches[1][0];
123 123
                 }
124 124
             }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      *
132 132
      * @throws InvalidMessageDateException
133 133
      */
134
-    protected function parse(){
134
+    protected function parse() {
135 135
         $header = $this->rfc822_parse_headers($this->raw);
136 136
 
137 137
         $this->extractAddresses($header);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         $this->parseDate($header);
150 150
         foreach ($header as $key => $value) {
151 151
             $key = trim(rtrim(strtolower($key)));
152
-            if(!isset($this->attributes[$key])){
152
+            if (!isset($this->attributes[$key])) {
153 153
                 $this->attributes[$key] = $value;
154 154
             }
155 155
         }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      *
166 166
      * @return object
167 167
      */
168
-    public function rfc822_parse_headers($raw_headers){
168
+    public function rfc822_parse_headers($raw_headers) {
169 169
         $headers = [];
170 170
         $imap_headers = [];
171 171
         if (extension_loaded('imap')) {
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 
175 175
         $lines = explode("\r\n", $raw_headers);
176 176
         $prev_header = null;
177
-        foreach($lines as $line) {
177
+        foreach ($lines as $line) {
178 178
             if (substr($line, 0, 1) === "\n") {
179 179
                 $line = substr($line, 1);
180 180
             }
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
                     }
195 195
                     if (is_array($headers[$prev_header])) {
196 196
                         $headers[$prev_header][] = $line;
197
-                    }else{
197
+                    }else {
198 198
                         $headers[$prev_header] .= $line;
199 199
                     }
200 200
                 }
201
-            }else{
201
+            }else {
202 202
                 if (($pos = strpos($line, ":")) > 0) {
203 203
                     $key = trim(rtrim(strtolower(substr($line, 0, $pos))));
204 204
                     $value = trim(rtrim(strtolower(substr($line, $pos + 1))));
@@ -208,10 +208,10 @@  discard block
 block discarded – undo
208 208
             }
209 209
         }
210 210
 
211
-        foreach($headers as $key => $values) {
211
+        foreach ($headers as $key => $values) {
212 212
             if (isset($imap_headers[$key])) continue;
213 213
             $value = null;
214
-            switch($key){
214
+            switch ($key) {
215 215
                 case 'from':
216 216
                 case 'to':
217 217
                 case 'cc':
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                     break;
227 227
                 default:
228 228
                     if (is_array($values)) {
229
-                        foreach($values as $k => $v) {
229
+                        foreach ($values as $k => $v) {
230 230
                             if ($v == "") {
231 231
                                 unset($values[$k]);
232 232
                             }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
                             $value = implode(" ", $values);
239 239
                         } elseif ($available_values > 2) {
240 240
                             $value = array_values($values);
241
-                        } else {
241
+                        }else {
242 242
                             $value = "";
243 243
                         }
244 244
                     }
@@ -258,12 +258,12 @@  discard block
 block discarded – undo
258 258
      * @return array The decoded elements are returned in an array of objects, where each
259 259
      * object has two properties, charset and text.
260 260
      */
261
-    public function mime_header_decode($text){
261
+    public function mime_header_decode($text) {
262 262
         if (extension_loaded('imap')) {
263 263
             return \imap_mime_header_decode($text);
264 264
         }
265 265
         $charset = $this->getEncoding($text);
266
-        return [(object)[
266
+        return [(object) [
267 267
             "charset" => $charset,
268 268
             "text" => $this->convertEncoding($text, $charset)
269 269
         ]];
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
         try {
318 318
             if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
319 319
                 return iconv($from, $to, $str);
320
-            } else {
320
+            }else {
321 321
                 if (!$from) {
322 322
                     return mb_convert_encoding($str, $to);
323 323
                 }
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
             if (strstr($from, '-')) {
328 328
                 $from = str_replace('-', '', $from);
329 329
                 return $this->convertEncoding($str, $from, $to);
330
-            } else {
330
+            }else {
331 331
                 return $str;
332 332
             }
333 333
         }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
             }
349 349
         }elseif (property_exists($structure, 'charset')) {
350 350
             return EncodingAliases::get($structure->charset, $this->fallback_encoding);
351
-        }elseif (is_string($structure) === true){
351
+        }elseif (is_string($structure) === true) {
352 352
             return mb_detect_encoding($structure);
353 353
         }
354 354
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         $decoder = $this->config['decoder']['message'];
367 367
 
368 368
         if ($value !== null) {
369
-            if($decoder === 'utf-8' && extension_loaded('imap')) {
369
+            if ($decoder === 'utf-8' && extension_loaded('imap')) {
370 370
                 $value = \imap_utf8($value);
371 371
                 if (strpos(strtolower($value), '=?utf-8?') === 0) {
372 372
                     $value = mb_decode_mimeheader($value);
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
                 if ($this->notDecoded($original_value, $value)) {
375 375
                     $decoded_value = $this->mime_header_decode($value);
376 376
                     if (count($decoded_value) > 0) {
377
-                        if(property_exists($decoded_value[0], "text")) {
377
+                        if (property_exists($decoded_value[0], "text")) {
378 378
                             $value = $decoded_value[0]->text;
379 379
                         }
380 380
                     }
381 381
                 }
382
-            }elseif($decoder === 'iconv') {
382
+            }elseif ($decoder === 'iconv') {
383 383
                 $value = iconv_mime_decode($value);
384
-            }else{
384
+            }else {
385 385
                 $value = mb_decode_mimeheader($value);
386 386
             }
387 387
 
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
      * Try to extract the priority from a given raw header string
402 402
      */
403 403
     private function findPriority() {
404
-        if(($priority = $this->get("x-priority")) === null) return;
405
-        switch($priority){
404
+        if (($priority = $this->get("x-priority")) === null) return;
405
+        switch ($priority) {
406 406
             case IMAP::MESSAGE_PRIORITY_HIGHEST;
407 407
                 $priority = IMAP::MESSAGE_PRIORITY_HIGHEST;
408 408
                 break;
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
      */
435 435
     private function decodeAddresses($values) {
436 436
         $addresses = [];
437
-        foreach($values as $address) {
437
+        foreach ($values as $address) {
438 438
             if (preg_match(
439 439
                 '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/',
440 440
                 $address,
441 441
                 $matches
442
-            )){
442
+            )) {
443 443
                 $name = trim(rtrim($matches["name"]));
444 444
                 $email = trim(rtrim($matches["email"]));
445 445
                 list($mailbox, $host) = array_pad(explode("@", $email), 2, null);
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
      * @param object $header
459 459
      */
460 460
     private function extractAddresses($header) {
461
-        foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key){
461
+        foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key) {
462 462
             if (property_exists($header, $key)) {
463 463
                 $this->attributes[$key] = $this->parseAddresses($header->$key);
464 464
             }
@@ -485,10 +485,10 @@  discard block
 block discarded – undo
485 485
             }
486 486
             if (!property_exists($address, 'personal')) {
487 487
                 $address->personal = false;
488
-            } else {
488
+            }else {
489 489
                 $personalParts = $this->mime_header_decode($address->personal);
490 490
 
491
-                if(is_array($personalParts)) {
491
+                if (is_array($personalParts)) {
492 492
                     $address->personal = '';
493 493
                     foreach ($personalParts as $p) {
494 494
                         $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p));
@@ -508,18 +508,18 @@  discard block
 block discarded – undo
508 508
     /**
509 509
      * Search and extract potential header extensions
510 510
      */
511
-    private function extractHeaderExtensions(){
511
+    private function extractHeaderExtensions() {
512 512
         foreach ($this->attributes as $key => $value) {
513 513
             // Only parse strings and don't parse any attributes like the user-agent
514 514
             if (is_string($value) === true && in_array($key, ["user-agent"]) === false) {
515
-                if (($pos = strpos($value, ";")) !== false){
515
+                if (($pos = strpos($value, ";")) !== false) {
516 516
                     $original = substr($value, 0, $pos);
517 517
                     $this->attributes[$key] = trim(rtrim($original));
518 518
 
519 519
                     // Get all potential extensions
520 520
                     $extensions = explode(";", substr($value, $pos + 1));
521
-                    foreach($extensions as $extension) {
522
-                        if (($pos = strpos($extension, "=")) !== false){
521
+                    foreach ($extensions as $extension) {
522
+                        if (($pos = strpos($extension, "=")) !== false) {
523 523
                             $key = substr($extension, 0, $pos);
524 524
                             $value = substr($extension, $pos + 1);
525 525
                             $value = str_replace('"', "", $value);
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
             $parsed_date = null;
557 557
             $date = $header->date;
558 558
 
559
-            if(preg_match('/\+0580/', $date)) {
559
+            if (preg_match('/\+0580/', $date)) {
560 560
                 $date = str_replace('+0580', '+0530', $date);
561 561
             }
562 562
 
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
                         $date = trim(array_pop($array));
580 580
                         break;
581 581
                 }
582
-                try{
582
+                try {
583 583
                     $parsed_date = Carbon::parse($date);
584 584
                 } catch (\Exception $_e) {
585 585
                     throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e);
Please login to merge, or discard this patch.
Braces   +13 added lines, -9 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                 if ($prev_header !== null) {
186 186
                     $headers[$prev_header][] = $line;
187 187
                 }
188
-            }elseif (substr($line, 0, 1) === " ") {
188
+            } elseif (substr($line, 0, 1) === " ") {
189 189
                 $line = substr($line, 1);
190 190
                 $line = trim(rtrim($line));
191 191
                 if ($prev_header !== null) {
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
                     }
195 195
                     if (is_array($headers[$prev_header])) {
196 196
                         $headers[$prev_header][] = $line;
197
-                    }else{
197
+                    } else{
198 198
                         $headers[$prev_header] .= $line;
199 199
                     }
200 200
                 }
201
-            }else{
201
+            } else{
202 202
                 if (($pos = strpos($line, ":")) > 0) {
203 203
                     $key = trim(rtrim(strtolower(substr($line, 0, $pos))));
204 204
                     $value = trim(rtrim(strtolower(substr($line, $pos + 1))));
@@ -209,7 +209,9 @@  discard block
 block discarded – undo
209 209
         }
210 210
 
211 211
         foreach($headers as $key => $values) {
212
-            if (isset($imap_headers[$key])) continue;
212
+            if (isset($imap_headers[$key])) {
213
+                continue;
214
+            }
213 215
             $value = null;
214 216
             switch($key){
215 217
                 case 'from':
@@ -346,9 +348,9 @@  discard block
 block discarded – undo
346 348
                     return EncodingAliases::get($parameter->value, $this->fallback_encoding);
347 349
                 }
348 350
             }
349
-        }elseif (property_exists($structure, 'charset')) {
351
+        } elseif (property_exists($structure, 'charset')) {
350 352
             return EncodingAliases::get($structure->charset, $this->fallback_encoding);
351
-        }elseif (is_string($structure) === true){
353
+        } elseif (is_string($structure) === true){
352 354
             return mb_detect_encoding($structure);
353 355
         }
354 356
 
@@ -379,9 +381,9 @@  discard block
 block discarded – undo
379 381
                         }
380 382
                     }
381 383
                 }
382
-            }elseif($decoder === 'iconv') {
384
+            } elseif($decoder === 'iconv') {
383 385
                 $value = iconv_mime_decode($value);
384
-            }else{
386
+            } else{
385 387
                 $value = mb_decode_mimeheader($value);
386 388
             }
387 389
 
@@ -401,7 +403,9 @@  discard block
 block discarded – undo
401 403
      * Try to extract the priority from a given raw header string
402 404
      */
403 405
     private function findPriority() {
404
-        if(($priority = $this->get("x-priority")) === null) return;
406
+        if(($priority = $this->get("x-priority")) === null) {
407
+            return;
408
+        }
405 409
         switch($priority){
406 410
             case IMAP::MESSAGE_PRIORITY_HIGHEST;
407 411
                 $priority = IMAP::MESSAGE_PRIORITY_HIGHEST;
Please login to merge, or discard this patch.