Passed
Push — master ( 81c85c...b3bf46 )
by Malte
02:06
created
src/Query/Query.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
         $this->setClient($client);
81 81
 
82 82
         $this->sequence = ClientManager::get('options.sequence', IMAP::ST_MSGN);
83
-        if(ClientManager::get('options.fetch') === IMAP::FT_PEEK) $this->leaveUnread();
83
+        if (ClientManager::get('options.fetch') === IMAP::FT_PEEK) $this->leaveUnread();
84 84
 
85 85
         if (ClientManager::get('options.fetch_order') === 'desc') {
86 86
             $this->fetch_order = 'desc';
87
-        } else {
87
+        }else {
88 88
             $this->fetch_order = 'asc';
89 89
         }
90 90
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     /**
99 99
      * Instance boot method for additional functionality
100 100
      */
101
-    protected function boot(){}
101
+    protected function boot() {}
102 102
 
103 103
     /**
104 104
      * Parse a given value
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
      *
107 107
      * @return string
108 108
      */
109
-    protected function parse_value($value){
110
-        switch(true){
109
+    protected function parse_value($value) {
110
+        switch (true) {
111 111
             case $value instanceof \Carbon\Carbon:
112 112
                 $value = $value->format($this->date_format);
113 113
                 break;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      * @throws MessageSearchValidationException
125 125
      */
126 126
     protected function parse_date($date) {
127
-        if($date instanceof \Carbon\Carbon) return $date;
127
+        if ($date instanceof \Carbon\Carbon) return $date;
128 128
 
129 129
         try {
130 130
             $date = Carbon::parse($date);
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      * @return Collection
176 176
      * @throws GetMessagesFailedException
177 177
      */
178
-    protected function search(){
178
+    protected function search() {
179 179
         $this->generate_query();
180 180
 
181 181
         try {
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
                     $raw_flag = isset($raw_flags[$uid]) ? $raw_flags[$uid] : [];
241 241
 
242 242
                     $message = Message::make($uid, $msglist, $this->getClient(), $raw_header, $raw_content, $raw_flag, $this->getFetchOptions(), $this->sequence);
243
-                    switch ($message_key){
243
+                    switch ($message_key) {
244 244
                         case 'number':
245 245
                             $message_key = $message->getMessageNo();
246 246
                             break;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 
263 263
             return $messages;
264 264
         } catch (\Exception $e) {
265
-            throw new GetMessagesFailedException($e->getMessage(),0, $e);
265
+            throw new GetMessagesFailedException($e->getMessage(), 0, $e);
266 266
         }
267 267
     }
268 268
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      * @throws MessageHeaderFetchingException
281 281
      * @throws \Webklex\PHPIMAP\Exceptions\EventNotFoundException
282 282
      */
283
-    public function getMessage($uid, $msglist = null, $sequence = null){
283
+    public function getMessage($uid, $msglist = null, $sequence = null) {
284 284
         return new Message($uid, $msglist, $this->getClient(), $this->getFetchOptions(), $this->getFetchBody(), $this->getFetchFlags(), $sequence ? $sequence : $this->sequence);
285 285
     }
286 286
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
      * @return LengthAwarePaginator
294 294
      * @throws GetMessagesFailedException
295 295
      */
296
-    public function paginate($per_page = 5, $page = null, $page_name = 'imap_page'){
296
+    public function paginate($per_page = 5, $page = null, $page_name = 'imap_page') {
297 297
         if (
298 298
                $page === null
299 299
             && isset($_GET[$page_name])
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
         $this->query->each(function($statement) use(&$query) {
320 320
             if (count($statement) == 1) {
321 321
                 $query .= $statement[0];
322
-            } else {
323
-                if($statement[1] === null){
322
+            }else {
323
+                if ($statement[1] === null) {
324 324
                     $query .= $statement[0];
325
-                }else{
325
+                }else {
326 326
                     $query .= $statement[0].' "'.$statement[1].'"';
327 327
                 }
328 328
             }
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
      * @return $this
353 353
      */
354 354
     public function limit($limit, $page = 1) {
355
-        if($page >= 1) $this->page = $page;
355
+        if ($page >= 1) $this->page = $page;
356 356
         $this->limit = $limit;
357 357
 
358 358
         return $this;
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,7 +80,9 @@  discard block
 block discarded – undo
80 80
         $this->setClient($client);
81 81
 
82 82
         $this->sequence = ClientManager::get('options.sequence', IMAP::ST_MSGN);
83
-        if(ClientManager::get('options.fetch') === IMAP::FT_PEEK) $this->leaveUnread();
83
+        if(ClientManager::get('options.fetch') === IMAP::FT_PEEK) {
84
+            $this->leaveUnread();
85
+        }
84 86
 
85 87
         if (ClientManager::get('options.fetch_order') === 'desc') {
86 88
             $this->fetch_order = 'desc';
@@ -124,7 +126,9 @@  discard block
 block discarded – undo
124 126
      * @throws MessageSearchValidationException
125 127
      */
126 128
     protected function parse_date($date) {
127
-        if($date instanceof \Carbon\Carbon) return $date;
129
+        if($date instanceof \Carbon\Carbon) {
130
+            return $date;
131
+        }
128 132
 
129 133
         try {
130 134
             $date = Carbon::parse($date);
@@ -322,7 +326,7 @@  discard block
 block discarded – undo
322 326
             } else {
323 327
                 if($statement[1] === null){
324 328
                     $query .= $statement[0];
325
-                }else{
329
+                } else{
326 330
                     $query .= $statement[0].' "'.$statement[1].'"';
327 331
                 }
328 332
             }
@@ -352,7 +356,9 @@  discard block
 block discarded – undo
352 356
      * @return $this
353 357
      */
354 358
     public function limit($limit, $page = 1) {
355
-        if($page >= 1) $this->page = $page;
359
+        if($page >= 1) {
360
+            $this->page = $page;
361
+        }
356 362
         $this->limit = $limit;
357 363
 
358 364
         return $this;
Please login to merge, or discard this patch.
src/Message.php 2 patches
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_flags = false, $sequence = null) {
201 201
 
202 202
         $default_mask = $client->getDefaultMessageMask();
203
-        if($default_mask != null) {
203
+        if ($default_mask != null) {
204 204
             $this->mask = $default_mask;
205 205
         }
206 206
         $this->events["message"] = $client->getDefaultEvents("message");
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         if ($this->sequence === IMAP::ST_UID) {
225 225
             $this->uid = $uid;
226 226
             $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
227
-        }else{
227
+        }else {
228 228
             $this->msgn = $uid;
229 229
             $this->uid = $this->client->getConnection()->getUid($this->msgn);
230 230
         }
@@ -264,13 +264,13 @@  discard block
 block discarded – undo
264 264
      * @throws MessageContentFetchingException
265 265
      * @throws \ReflectionException
266 266
      */
267
-    public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null){
267
+    public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null) {
268 268
         $reflection = new \ReflectionClass(self::class);
269 269
         /** @var self $instance */
270 270
         $instance = $reflection->newInstanceWithoutConstructor();
271 271
 
272 272
         $default_mask = $client->getDefaultMessageMask();
273
-        if($default_mask != null) {
273
+        if ($default_mask != null) {
274 274
             $instance->setMask($default_mask);
275 275
         }
276 276
         $instance->setEvents([
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         if ($instance->getSequence() === IMAP::ST_UID) {
290 290
             $instance->setUid($uid);
291 291
             $instance->setMsglist($msglist);
292
-        }else{
292
+        }else {
293 293
             $instance->setMsgn($uid, $msglist);
294 294
         }
295 295
 
@@ -317,13 +317,13 @@  discard block
 block discarded – undo
317 317
      * @throws MethodNotFoundException
318 318
      */
319 319
     public function __call($method, $arguments) {
320
-        if(strtolower(substr($method, 0, 3)) === 'get') {
320
+        if (strtolower(substr($method, 0, 3)) === 'get') {
321 321
             $name = Str::snake(substr($method, 3));
322 322
             return $this->get($name);
323 323
         }elseif (strtolower(substr($method, 0, 3)) === 'set') {
324 324
             $name = Str::snake(substr($method, 3));
325 325
 
326
-            if(in_array($name, array_keys($this->attributes))) {
326
+            if (in_array($name, array_keys($this->attributes))) {
327 327
                 $this->attributes[$name] = array_pop($arguments);
328 328
 
329 329
                 return $this->attributes[$name];
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
      * @return mixed|null
365 365
      */
366 366
     public function get($name) {
367
-        if(isset($this->attributes[$name])) {
367
+        if (isset($this->attributes[$name])) {
368 368
             return $this->attributes[$name];
369 369
         }
370 370
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
      *
439 439
      * @throws InvalidMessageDateException
440 440
      */
441
-    public function parseRawHeader($raw_header){
441
+    public function parseRawHeader($raw_header) {
442 442
         $this->header = new Header($raw_header);
443 443
     }
444 444
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
     public function parseRawFlags($raw_flags) {
450 450
         $this->flags = FlagCollection::make([]);
451 451
 
452
-        foreach($raw_flags as $flag) {
453
-            if (strpos($flag, "\\") === 0){
452
+        foreach ($raw_flags as $flag) {
453
+            if (strpos($flag, "\\") === 0) {
454 454
                 $flag = substr($flag, 1);
455 455
             }
456 456
             $flag_key = strtolower($flag);
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 
554 554
         if ($part->isAttachment()) {
555 555
             $this->fetchAttachment($part);
556
-        }else{
556
+        }else {
557 557
             $encoding = $this->getEncoding($part);
558 558
 
559 559
             $content = $this->decodeString($part->content, $part->encoding);
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
         if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) {
592 592
             if ($oAttachment->getId() !== null) {
593 593
                 $this->attachments->put($oAttachment->getId(), $oAttachment);
594
-            } else {
594
+            }else {
595 595
                 $this->attachments->push($oAttachment);
596 596
             }
597 597
         }
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 
726 726
         if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
727 727
             return @iconv($from, $to.'//IGNORE', $str);
728
-        } else {
728
+        }else {
729 729
             if (!$from) {
730 730
                 return mb_convert_encoding($str, $to);
731 731
             }
@@ -746,9 +746,9 @@  discard block
 block discarded – undo
746 746
                     return EncodingAliases::get($parameter->value);
747 747
                 }
748 748
             }
749
-        }elseif (property_exists($structure, 'charset')){
749
+        }elseif (property_exists($structure, 'charset')) {
750 750
             return EncodingAliases::get($structure->charset);
751
-        }elseif (is_string($structure) === true){
751
+        }elseif (is_string($structure) === true) {
752 752
             return mb_detect_encoding($structure);
753 753
         }
754 754
 
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
      * @throws Exceptions\ConnectionFailedException
763 763
      * @throws Exceptions\FolderFetchingException
764 764
      */
765
-    public function getFolder(){
765
+    public function getFolder() {
766 766
         return $this->client->getFolder($this->folder_path);
767 767
     }
768 768
 
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
      * @throws Exceptions\FolderFetchingException
778 778
      * @throws Exceptions\GetMessagesFailedException
779 779
      */
780
-    public function thread($sent_folder = null, &$thread = null, $folder = null){
780
+    public function thread($sent_folder = null, &$thread = null, $folder = null) {
781 781
         $thread = $thread ? $thread : MessageCollection::make([]);
782
-        $folder = $folder ? $folder :  $this->getFolder();
782
+        $folder = $folder ? $folder : $this->getFolder();
783 783
         $sent_folder = $sent_folder ? $sent_folder : $this->client->getFolder(ClientManager::get("options.common_folders.sent", "INBOX/Sent"));
784 784
 
785 785
         /** @var Message $message */
786
-        foreach($thread as $message) {
786
+        foreach ($thread as $message) {
787 787
             if ($message->message_id == $this->message_id) {
788 788
                 return $thread;
789 789
             }
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
         });
805 805
 
806 806
         if (is_array($this->in_reply_to)) {
807
-            foreach($this->in_reply_to as $in_reply_to) {
807
+            foreach ($this->in_reply_to as $in_reply_to) {
808 808
                 $folder->query()->messageId($in_reply_to)
809 809
                     ->setFetchBody($this->getFetchBodyOption())
810 810
                     ->leaveUnread()->get()->each(function($message) use(&$thread, $folder, $sent_folder){
@@ -849,13 +849,13 @@  discard block
 block discarded – undo
849 849
 
850 850
             $this->client->openFolder($this->folder_path);
851 851
             if ($this->client->getConnection()->copyMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID) == true) {
852
-                if($expunge) $this->client->expunge();
852
+                if ($expunge) $this->client->expunge();
853 853
 
854 854
                 $this->client->openFolder($folder->path);
855 855
 
856 856
                 if ($this->sequence === IMAP::ST_UID) {
857 857
                     $sequence_id = $next_uid;
858
-                }else{
858
+                }else {
859 859
                     $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
860 860
                 }
861 861
 
@@ -896,13 +896,13 @@  discard block
 block discarded – undo
896 896
 
897 897
             $this->client->openFolder($this->folder_path);
898 898
             if ($this->client->getConnection()->moveMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID) == true) {
899
-                if($expunge) $this->client->expunge();
899
+                if ($expunge) $this->client->expunge();
900 900
 
901 901
                 $this->client->openFolder($folder->path);
902 902
 
903 903
                 if ($this->sequence === IMAP::ST_UID) {
904 904
                     $sequence_id = $next_uid;
905
-                }else{
905
+                }else {
906 906
                     $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
907 907
                 }
908 908
 
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
      */
929 929
     public function delete($expunge = true) {
930 930
         $status = $this->setFlag("Deleted");
931
-        if($expunge) $this->client->expunge();
931
+        if ($expunge) $this->client->expunge();
932 932
 
933 933
         $event = $this->getEvent("message", "deleted");
934 934
         $event::dispatch($this);
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
      */
948 948
     public function restore($expunge = true) {
949 949
         $status = $this->unsetFlag("Deleted");
950
-        if($expunge) $this->client->expunge();
950
+        if ($expunge) $this->client->expunge();
951 951
 
952 952
         $event = $this->getEvent("message", "restored");
953 953
         $event::dispatch($this);
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
      *
1103 1103
      * @return Structure|null
1104 1104
      */
1105
-    public function getStructure(){
1105
+    public function getStructure() {
1106 1106
         return $this->structure;
1107 1107
     }
1108 1108
 
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
      *
1129 1129
      * @return array
1130 1130
      */
1131
-    public function getAttributes(){
1131
+    public function getAttributes() {
1132 1132
         return array_merge($this->attributes, $this->header->getAttributes());
1133 1133
     }
1134 1134
 
@@ -1138,8 +1138,8 @@  discard block
 block discarded – undo
1138 1138
      *
1139 1139
      * @return $this
1140 1140
      */
1141
-    public function setMask($mask){
1142
-        if(class_exists($mask)){
1141
+    public function setMask($mask) {
1142
+        if (class_exists($mask)) {
1143 1143
             $this->mask = $mask;
1144 1144
         }
1145 1145
 
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
      *
1152 1152
      * @return string
1153 1153
      */
1154
-    public function getMask(){
1154
+    public function getMask() {
1155 1155
         return $this->mask;
1156 1156
     }
1157 1157
 
@@ -1162,9 +1162,9 @@  discard block
 block discarded – undo
1162 1162
      * @return mixed
1163 1163
      * @throws MaskNotFoundException
1164 1164
      */
1165
-    public function mask($mask = null){
1165
+    public function mask($mask = null) {
1166 1166
         $mask = $mask !== null ? $mask : $this->mask;
1167
-        if(class_exists($mask)){
1167
+        if (class_exists($mask)) {
1168 1168
             return new $mask($this);
1169 1169
         }
1170 1170
 
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
      *
1178 1178
      * @return $this
1179 1179
      */
1180
-    public function setFolderPath($folder_path){
1180
+    public function setFolderPath($folder_path) {
1181 1181
         $this->folder_path = $folder_path;
1182 1182
 
1183 1183
         return $this;
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
      *
1190 1190
      * @return $this
1191 1191
      */
1192
-    public function setConfig($config){
1192
+    public function setConfig($config) {
1193 1193
         $this->config = $config;
1194 1194
 
1195 1195
         return $this;
@@ -1201,7 +1201,7 @@  discard block
 block discarded – undo
1201 1201
      *
1202 1202
      * @return $this
1203 1203
      */
1204
-    public function setAttachments($attachments){
1204
+    public function setAttachments($attachments) {
1205 1205
         $this->attachments = $attachments;
1206 1206
 
1207 1207
         return $this;
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
      *
1214 1214
      * @return $this
1215 1215
      */
1216
-    public function setFlags($flags){
1216
+    public function setFlags($flags) {
1217 1217
         $this->flags = $flags;
1218 1218
 
1219 1219
         return $this;
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
      * @throws Exceptions\ConnectionFailedException
1227 1227
      * @return $this
1228 1228
      */
1229
-    public function setClient($client){
1229
+    public function setClient($client) {
1230 1230
         $this->client = $client;
1231 1231
         $this->client->openFolder($this->folder_path);
1232 1232
 
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
      * @throws Exceptions\RuntimeException
1242 1242
      * @return $this
1243 1243
      */
1244
-    public function setUid($uid){
1244
+    public function setUid($uid) {
1245 1245
         $this->uid = $uid;
1246 1246
         $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
1247 1247
         $this->msglist = null;
@@ -1258,7 +1258,7 @@  discard block
 block discarded – undo
1258 1258
      * @throws Exceptions\RuntimeException
1259 1259
      * @return $this
1260 1260
      */
1261
-    public function setMsgn($msgn, $msglist = null){
1261
+    public function setMsgn($msgn, $msglist = null) {
1262 1262
         $this->msgn = $msgn;
1263 1263
         $this->msglist = $msglist;
1264 1264
         $this->uid = $this->client->getConnection()->getUid($this->msgn);
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
      *
1272 1272
      * @return int
1273 1273
      */
1274
-    public function getSequence(){
1274
+    public function getSequence() {
1275 1275
         return $this->sequence;
1276 1276
     }
1277 1277
 
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
      *
1281 1281
      * @return int
1282 1282
      */
1283
-    public function getSequenceId(){
1283
+    public function getSequenceId() {
1284 1284
         return $this->sequence === IMAP::ST_UID ? $this->uid : $this->msgn;
1285 1285
     }
1286 1286
 }
Please login to merge, or discard this patch.
Braces   +21 added lines, -13 removed lines patch added patch discarded remove patch
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         if ($this->sequence === IMAP::ST_UID) {
225 225
             $this->uid = $uid;
226 226
             $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
227
-        }else{
227
+        } else{
228 228
             $this->msgn = $uid;
229 229
             $this->uid = $this->client->getConnection()->getUid($this->msgn);
230 230
         }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         if ($instance->getSequence() === IMAP::ST_UID) {
290 290
             $instance->setUid($uid);
291 291
             $instance->setMsglist($msglist);
292
-        }else{
292
+        } else{
293 293
             $instance->setMsgn($uid, $msglist);
294 294
         }
295 295
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         if(strtolower(substr($method, 0, 3)) === 'get') {
321 321
             $name = Str::snake(substr($method, 3));
322 322
             return $this->get($name);
323
-        }elseif (strtolower(substr($method, 0, 3)) === 'set') {
323
+        } elseif (strtolower(substr($method, 0, 3)) === 'set') {
324 324
             $name = Str::snake(substr($method, 3));
325 325
 
326 326
             if(in_array($name, array_keys($this->attributes))) {
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             if ($this->getFlags()->get("seen") == null) {
506 506
                 $this->unsetFlag("Seen");
507 507
             }
508
-        }elseif ($this->getFlags()->get("seen") != null) {
508
+        } elseif ($this->getFlags()->get("seen") != null) {
509 509
             $this->setFlag("Seen");
510 510
         }
511 511
 
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 
554 554
         if ($part->isAttachment()) {
555 555
             $this->fetchAttachment($part);
556
-        }else{
556
+        } else{
557 557
             $encoding = $this->getEncoding($part);
558 558
 
559 559
             $content = $this->decodeString($part->content, $part->encoding);
@@ -746,9 +746,9 @@  discard block
 block discarded – undo
746 746
                     return EncodingAliases::get($parameter->value);
747 747
                 }
748 748
             }
749
-        }elseif (property_exists($structure, 'charset')){
749
+        } elseif (property_exists($structure, 'charset')){
750 750
             return EncodingAliases::get($structure->charset);
751
-        }elseif (is_string($structure) === true){
751
+        } elseif (is_string($structure) === true){
752 752
             return mb_detect_encoding($structure);
753 753
         }
754 754
 
@@ -849,13 +849,15 @@  discard block
 block discarded – undo
849 849
 
850 850
             $this->client->openFolder($this->folder_path);
851 851
             if ($this->client->getConnection()->copyMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID) == true) {
852
-                if($expunge) $this->client->expunge();
852
+                if($expunge) {
853
+                    $this->client->expunge();
854
+                }
853 855
 
854 856
                 $this->client->openFolder($folder->path);
855 857
 
856 858
                 if ($this->sequence === IMAP::ST_UID) {
857 859
                     $sequence_id = $next_uid;
858
-                }else{
860
+                } else{
859 861
                     $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
860 862
                 }
861 863
 
@@ -896,13 +898,15 @@  discard block
 block discarded – undo
896 898
 
897 899
             $this->client->openFolder($this->folder_path);
898 900
             if ($this->client->getConnection()->moveMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID) == true) {
899
-                if($expunge) $this->client->expunge();
901
+                if($expunge) {
902
+                    $this->client->expunge();
903
+                }
900 904
 
901 905
                 $this->client->openFolder($folder->path);
902 906
 
903 907
                 if ($this->sequence === IMAP::ST_UID) {
904 908
                     $sequence_id = $next_uid;
905
-                }else{
909
+                } else{
906 910
                     $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
907 911
                 }
908 912
 
@@ -928,7 +932,9 @@  discard block
 block discarded – undo
928 932
      */
929 933
     public function delete($expunge = true) {
930 934
         $status = $this->setFlag("Deleted");
931
-        if($expunge) $this->client->expunge();
935
+        if($expunge) {
936
+            $this->client->expunge();
937
+        }
932 938
 
933 939
         $event = $this->getEvent("message", "deleted");
934 940
         $event::dispatch($this);
@@ -947,7 +953,9 @@  discard block
 block discarded – undo
947 953
      */
948 954
     public function restore($expunge = true) {
949 955
         $status = $this->unsetFlag("Deleted");
950
-        if($expunge) $this->client->expunge();
956
+        if($expunge) {
957
+            $this->client->expunge();
958
+        }
951 959
 
952 960
         $event = $this->getEvent("message", "restored");
953 961
         $event::dispatch($this);
Please login to merge, or discard this patch.
src/Connection/Protocols/ImapProtocol.php 2 patches
Spacing   +46 added lines, -46 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
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
             // First two chars are still needed for the response code
258 258
             $tokens = [substr($tokens, 0, 2)];
259 259
         }
260
-        if (is_array($lines)){
260
+        if (is_array($lines)) {
261 261
             if ($this->debug) echo "<< ".json_encode($lines)."\n";
262
-        }else{
262
+        }else {
263 263
             if ($this->debug) echo "<< ".$lines."\n";
264 264
         }
265 265
 
@@ -284,27 +284,27 @@  discard block
 block discarded – undo
284 284
     public function sendRequest($command, $tokens = [], &$tag = null) {
285 285
         if (!$tag) {
286 286
             $this->noun++;
287
-            $tag = 'TAG' . $this->noun;
287
+            $tag = 'TAG'.$this->noun;
288 288
         }
289 289
 
290
-        $line = $tag . ' ' . $command;
290
+        $line = $tag.' '.$command;
291 291
 
292 292
         foreach ($tokens as $token) {
293 293
             if (is_array($token)) {
294
-                if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) {
294
+                if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) {
295 295
                     throw new RuntimeException('failed to write - connection closed?');
296 296
                 }
297 297
                 if (!$this->assumedNextLine('+ ')) {
298 298
                     throw new RuntimeException('failed to send literal string');
299 299
                 }
300 300
                 $line = $token[1];
301
-            } else {
302
-                $line .= ' ' . $token;
301
+            }else {
302
+                $line .= ' '.$token;
303 303
             }
304 304
         }
305 305
         if ($this->debug) echo ">> ".$line."\n";
306 306
 
307
-        if (fwrite($this->stream, $line . "\r\n") === false) {
307
+        if (fwrite($this->stream, $line."\r\n") === false) {
308 308
             throw new RuntimeException('failed to write - connection closed?');
309 309
         }
310 310
     }
@@ -334,9 +334,9 @@  discard block
 block discarded – undo
334 334
     public function escapeString($string) {
335 335
         if (func_num_args() < 2) {
336 336
             if (strpos($string, "\n") !== false) {
337
-                return ['{' . strlen($string) . '}', $string];
338
-            } else {
339
-                return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"';
337
+                return ['{'.strlen($string).'}', $string];
338
+            }else {
339
+                return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"';
340 340
             }
341 341
         }
342 342
         $result = [];
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
             }
362 362
             $result[] = $this->escapeList($v);
363 363
         }
364
-        return '(' . implode(' ', $result) . ')';
364
+        return '('.implode(' ', $result).')';
365 365
     }
366 366
 
367 367
     /**
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
                     error_log("got an extra server challenge: $response");
402 402
                     // respond with an empty response.
403 403
                     $this->sendRequest('');
404
-                } else {
404
+                }else {
405 405
                     if (preg_match('/^NO /i', $response) ||
406 406
                         preg_match('/^BAD /i', $response)) {
407 407
                         error_log("got failure response: $response");
408 408
                         return false;
409
-                    } else if (preg_match("/^OK /i", $response)) {
409
+                    }else if (preg_match("/^OK /i", $response)) {
410 410
                         return true;
411 411
                     }
412 412
                 }
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
      *
440 440
      * @return bool
441 441
      */
442
-    public function connected(){
442
+    public function connected() {
443 443
         return (boolean) $this->stream;
444 444
     }
445 445
 
@@ -486,10 +486,10 @@  discard block
 block discarded – undo
486 486
                     $result[strtolower($tokens[1])] = $tokens[0];
487 487
                     break;
488 488
                 case '[UIDVALIDITY':
489
-                    $result['uidvalidity'] = (int)$tokens[2];
489
+                    $result['uidvalidity'] = (int) $tokens[2];
490 490
                     break;
491 491
                 case '[UIDNEXT':
492
-                    $result['uidnext'] = (int)$tokens[2];
492
+                    $result['uidnext'] = (int) $tokens[2];
493 493
                     break;
494 494
                 default:
495 495
                     // ignore
@@ -543,17 +543,17 @@  discard block
 block discarded – undo
543 543
         if (is_array($from)) {
544 544
             $set = implode(',', $from);
545 545
         } elseif ($to === null) {
546
-            $set = (int)$from;
546
+            $set = (int) $from;
547 547
         } elseif ($to === INF) {
548
-            $set = (int)$from . ':*';
549
-        } else {
550
-            $set = (int)$from . ':' . (int)$to;
548
+            $set = (int) $from.':*';
549
+        }else {
550
+            $set = (int) $from.':'.(int) $to;
551 551
         }
552 552
 
553
-        $items = (array)$items;
553
+        $items = (array) $items;
554 554
         $itemList = $this->escapeList($items);
555 555
 
556
-        $this->sendRequest(($uid ? 'UID ' : '') . 'FETCH', [$set, $itemList], $tag);
556
+        $this->sendRequest(($uid ? 'UID ' : '').'FETCH', [$set, $itemList], $tag);
557 557
 
558 558
         $result = [];
559 559
         $tokens = null; // define $tokens variable before first use
@@ -568,9 +568,9 @@  discard block
 block discarded – undo
568 568
                 $count = count($tokens[2]);
569 569
                 if ($tokens[2][$count - 2] == 'UID') {
570 570
                     $uidKey = $count - 1;
571
-                } else if ($tokens[2][0] == 'UID') {
571
+                }else if ($tokens[2][0] == 'UID') {
572 572
                     $uidKey = 1;
573
-                } else {
573
+                }else {
574 574
                     $uidKey = array_search('UID', $tokens[2]) + 1;
575 575
                 }
576 576
             }
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
                     $data = $tokens[2][1];
587 587
                 } elseif ($uid && $tokens[2][2] == $items[0]) {
588 588
                     $data = $tokens[2][3];
589
-                } else {
589
+                }else {
590 590
                     // maybe the server send an other field we didn't wanted
591 591
                     $count = count($tokens[2]);
592 592
                     // we start with 2, because 0 was already checked
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
                         break;
599 599
                     }
600 600
                 }
601
-            } else {
601
+            }else {
602 602
                 $data = [];
603 603
                 while (key($tokens[2]) !== null) {
604 604
                     $data[current($tokens[2])] = next($tokens[2]);
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
             }
616 616
             if ($uid) {
617 617
                 $result[$tokens[2][$uidKey]] = $data;
618
-            }else{
618
+            }else {
619 619
                 $result[$tokens[0]] = $data;
620 620
             }
621 621
         }
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
      * @return array
650 650
      * @throws RuntimeException
651 651
      */
652
-    public function headers($uids, $rfc = "RFC822", $uid = false){
652
+    public function headers($uids, $rfc = "RFC822", $uid = false) {
653 653
         return $this->fetch(["$rfc.HEADER"], $uids, null, $uid);
654 654
     }
655 655
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
      * @return array
662 662
      * @throws RuntimeException
663 663
      */
664
-    public function flags($uids, $uid = false){
664
+    public function flags($uids, $uid = false) {
665 665
         return $this->fetch(["FLAGS"], $uids, null, $uid);
666 666
     }
667 667
 
@@ -746,22 +746,22 @@  discard block
 block discarded – undo
746 746
     public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = false) {
747 747
         $item = 'FLAGS';
748 748
         if ($mode == '+' || $mode == '-') {
749
-            $item = $mode . $item;
749
+            $item = $mode.$item;
750 750
         }
751 751
         if ($silent) {
752 752
             $item .= '.SILENT';
753 753
         }
754 754
 
755 755
         $flags = $this->escapeList($flags);
756
-        $set = (int)$from;
756
+        $set = (int) $from;
757 757
         if ($to !== null) {
758
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
758
+            $set .= ':'.($to == INF ? '*' : (int) $to);
759 759
         }
760 760
 
761 761
         $result = $this->requestAndResponse('STORE', [$set, $item, $flags], $silent);
762 762
 
763 763
         if ($silent) {
764
-            return (bool)$result;
764
+            return (bool) $result;
765 765
         }
766 766
 
767 767
         $tokens = $result;
@@ -812,9 +812,9 @@  discard block
 block discarded – undo
812 812
      * @throws RuntimeException
813 813
      */
814 814
     public function copyMessage($folder, $from, $to = null, $uid = false) {
815
-        $set = (int)$from;
815
+        $set = (int) $from;
816 816
         if ($to !== null) {
817
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
817
+            $set .= ':'.($to == INF ? '*' : (int) $to);
818 818
         }
819 819
 
820 820
         return $this->requestAndResponse('COPY', [$set, $this->escapeString($folder)], true);
@@ -832,9 +832,9 @@  discard block
 block discarded – undo
832 832
      * @throws RuntimeException
833 833
      */
834 834
     public function moveMessage($folder, $from, $to = null, $uid = false) {
835
-        $set = (int)$from;
835
+        $set = (int) $from;
836 836
         if ($to !== null) {
837
-            $set .= ':' . ($to == INF ? '*' : (int)$to);
837
+            $set .= ':'.($to == INF ? '*' : (int) $to);
838 838
         }
839 839
 
840 840
         return $this->requestAndResponse('MOVE', [$set, $this->escapeString($folder)], true);
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
         $uids = $this->getUid();
1003 1003
         $ids = [];
1004 1004
         foreach ($uids as $msgn => $v) {
1005
-            if ( ($to >= $msgn && $from <= $msgn) || ($to === "*" && $from <= $msgn) ){
1005
+            if (($to >= $msgn && $from <= $msgn) || ($to === "*" && $from <= $msgn)) {
1006 1006
                 $ids[] = $msgn;
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   +17 added lines, -8 removed lines patch added patch discarded remove patch
@@ -258,9 +258,13 @@  discard block
 block discarded – undo
258 258
             $tokens = [substr($tokens, 0, 2)];
259 259
         }
260 260
         if (is_array($lines)){
261
-            if ($this->debug) echo "<< ".json_encode($lines)."\n";
262
-        }else{
263
-            if ($this->debug) echo "<< ".$lines."\n";
261
+            if ($this->debug) {
262
+                echo "<< ".json_encode($lines)."\n";
263
+            }
264
+        } else{
265
+            if ($this->debug) {
266
+                echo "<< ".$lines."\n";
267
+            }
264 268
         }
265 269
 
266 270
         // last line has response code
@@ -302,7 +306,9 @@  discard block
 block discarded – undo
302 306
                 $line .= ' ' . $token;
303 307
             }
304 308
         }
305
-        if ($this->debug) echo ">> ".$line."\n";
309
+        if ($this->debug) {
310
+            echo ">> ".$line."\n";
311
+        }
306 312
 
307 313
         if (fwrite($this->stream, $line . "\r\n") === false) {
308 314
             throw new RuntimeException('failed to write - connection closed?');
@@ -452,7 +458,9 @@  discard block
 block discarded – undo
452 458
     public function getCapabilities() {
453 459
         $response = $this->requestAndResponse('CAPABILITY');
454 460
 
455
-        if (!$response) return [];
461
+        if (!$response) {
462
+            return [];
463
+        }
456 464
 
457 465
         $capabilities = [];
458 466
         foreach ($response as $line) {
@@ -609,13 +617,14 @@  discard block
 block discarded – undo
609 617
             // if we want only one message we can ignore everything else and just return
610 618
             if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {
611 619
                 // we still need to read all lines
612
-                while (!$this->readLine($tokens, $tag))
613
-
620
+                while (!$this->readLine($tokens, $tag)) {
621
+                
614 622
                     return $data;
623
+                }
615 624
             }
616 625
             if ($uid) {
617 626
                 $result[$tokens[2][$uidKey]] = $data;
618
-            }else{
627
+            } else{
619 628
                 $result[$tokens[0]] = $data;
620 629
             }
621 630
         }
Please login to merge, or discard this patch.
src/Connection/Protocols/LegacyProtocol.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
             throw new AuthFailedException($message);
88 88
         }
89 89
 
90
-        if(!$this->stream) {
90
+        if (!$this->stream) {
91 91
             $errors = \imap_errors();
92 92
             $message = implode("; ", (is_array($errors) ? $errors : array()));
93 93
             throw new AuthFailedException($message);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         if (!$this->cert_validation) {
119 119
             $address .= '/novalidate-cert';
120 120
         }
121
-        if (in_array($this->encryption,['tls', 'notls', 'ssl'])) {
121
+        if (in_array($this->encryption, ['tls', 'notls', 'ssl'])) {
122 122
             $address .= '/'.$this->encryption;
123 123
         } elseif ($this->encryption === "starttls") {
124 124
             $address .= '/tls';
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      *
147 147
      * @return bool
148 148
      */
149
-    public function connected(){
149
+    public function connected() {
150 150
         return !$this->stream;
151 151
     }
152 152
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      *
219 219
      * @return array
220 220
      */
221
-    public function headers($uids, $rfc = "RFC822", $uid = false){
221
+    public function headers($uids, $rfc = "RFC822", $uid = false) {
222 222
         $result = [];
223 223
         $uids = is_array($uids) ? $uids : [$uids];
224 224
         foreach ($uids as $uid) {
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      *
235 235
      * @return array
236 236
      */
237
-    public function flags($uids, $uid = false){
237
+    public function flags($uids, $uid = false) {
238 238
         $result = [];
239 239
         $uids = is_array($uids) ? $uids : [$uids];
240 240
         foreach ($uids as $uid) {
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
             $flags = [];
243 243
             if (is_array($raw_flags) && isset($raw_flags[0])) {
244 244
                 $raw_flags = (array) $raw_flags[0];
245
-                foreach($raw_flags as $flag => $value) {
246
-                    if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false){
245
+                foreach ($raw_flags as $flag => $value) {
246
+                    if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false) {
247 247
                         $flags[] = "\\".ucfirst($flag);
248 248
                     }
249 249
                 }
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         if ($id === null) {
265 265
             $overview = $this->overview("1:*");
266 266
             $uids = [];
267
-            foreach($overview as $set){
267
+            foreach ($overview as $set) {
268 268
                 $uids[$set->msgno] = $set->uid;
269 269
             }
270 270
             return $uids;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * @return array
291 291
      */
292 292
     public function overview($sequence, $uid = false) {
293
-        return \imap_fetch_overview($this->stream, $sequence,$uid ? IMAP::FT_UID : IMAP::NIL);
293
+        return \imap_fetch_overview($this->stream, $sequence, $uid ? IMAP::FT_UID : IMAP::NIL);
294 294
     }
295 295
 
296 296
     /**
@@ -305,12 +305,12 @@  discard block
 block discarded – undo
305 305
         $result = [];
306 306
 
307 307
         $items = \imap_getmailboxes($this->stream, $this->getAddress(), $reference.$folder);
308
-        if(is_array($items)){
308
+        if (is_array($items)) {
309 309
             foreach ($items as $item) {
310 310
                 $name = $this->decodeFolderName($item->name);
311 311
                 $result[$name] = ['delimiter' => $item->delimiter, 'flags' => []];
312 312
             }
313
-        }else{
313
+        }else {
314 314
             throw new RuntimeException(\imap_last_error());
315 315
         }
316 316
 
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
     public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = false) {
333 333
         $flag = trim(is_array($flags) ? implode(" ", $flags) : $flags);
334 334
 
335
-        if ($mode == "+"){
335
+        if ($mode == "+") {
336 336
             $status = \imap_setflag_full($this->stream, $from, $flag, $uid ? IMAP::FT_UID : IMAP::NIL);
337
-        }else{
337
+        }else {
338 338
             $status = \imap_clearflag_full($this->stream, $from, $flag, $uid ? IMAP::FT_UID : IMAP::NIL);
339 339
         }
340 340
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
      */
357 357
     public function appendMessage($folder, $message, $flags = null, $date = null) {
358 358
         if ($date != null) {
359
-            if ($date instanceof \Carbon\Carbon){
359
+            if ($date instanceof \Carbon\Carbon) {
360 360
                 $date = $date->format('d-M-Y H:i:s O');
361 361
             }
362 362
             return \imap_append($this->stream, $folder, $message, $flags, $date);
@@ -493,14 +493,14 @@  discard block
 block discarded – undo
493 493
     /**
494 494
      * Enable the debug mode
495 495
      */
496
-    public function enableDebug(){
496
+    public function enableDebug() {
497 497
         $this->debug = true;
498 498
     }
499 499
 
500 500
     /**
501 501
      * Disable the debug mode
502 502
      */
503
-    public function disableDebug(){
503
+    public function disableDebug() {
504 504
         $this->debug = false;
505 505
     }
506 506
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                 $name = $this->decodeFolderName($item->name);
311 311
                 $result[$name] = ['delimiter' => $item->delimiter, 'flags' => []];
312 312
             }
313
-        }else{
313
+        } else{
314 314
             throw new RuntimeException(\imap_last_error());
315 315
         }
316 316
 
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 
335 335
         if ($mode == "+"){
336 336
             $status = \imap_setflag_full($this->stream, $from, $flag, $uid ? IMAP::FT_UID : IMAP::NIL);
337
-        }else{
337
+        } else{
338 338
             $status = \imap_clearflag_full($this->stream, $from, $flag, $uid ? IMAP::FT_UID : IMAP::NIL);
339 339
         }
340 340
 
Please login to merge, or discard this patch.