Completed
Push — master ( d77b64...e60d4a )
by Malte
02:19
created

Client::createFolder()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 13
rs 10
cc 4
nc 4
nop 2
1
<?php
2
/*
3
* File:     Client.php
4
* Category: -
5
* Author:   M. Goldenbaum
6
* Created:  19.01.17 22:21
7
* Updated:  -
8
*
9
* Description:
10
*  -
11
*/
12
13
namespace Webklex\PHPIMAP;
14
15
use Webklex\PHPIMAP\Connection\Protocols\ImapProtocol;
16
use Webklex\PHPIMAP\Connection\Protocols\LegacyProtocol;
17
use Webklex\PHPIMAP\Connection\Protocols\Protocol;
18
use Webklex\PHPIMAP\Connection\Protocols\ProtocolInterface;
19
use Webklex\PHPIMAP\Exceptions\AuthFailedException;
20
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
21
use Webklex\PHPIMAP\Exceptions\FolderFetchingException;
22
use Webklex\PHPIMAP\Exceptions\MaskNotFoundException;
23
use Webklex\PHPIMAP\Exceptions\ProtocolNotSupportedException;
24
use Webklex\PHPIMAP\Support\FolderCollection;
25
use Webklex\PHPIMAP\Support\Masks\AttachmentMask;
26
use Webklex\PHPIMAP\Support\Masks\MessageMask;
27
use Webklex\PHPIMAP\Traits\HasEvents;
28
29
/**
30
 * Class Client
31
 *
32
 * @package Webklex\PHPIMAP
33
 */
34
class Client {
35
    use HasEvents;
36
37
    /**
38
     * Connection resource
39
     *
40
     * @var boolean|Protocol|ProtocolInterface
41
     */
42
    public $connection = false;
43
44
    /**
45
     * Server hostname.
46
     *
47
     * @var string
48
     */
49
    public $host;
50
51
    /**
52
     * Server port.
53
     *
54
     * @var int
55
     */
56
    public $port;
57
58
    /**
59
     * Service protocol.
60
     *
61
     * @var int
62
     */
63
    public $protocol;
64
65
    /**
66
     * Server encryption.
67
     * Supported: none, ssl, tls, or notls.
68
     *
69
     * @var string
70
     */
71
    public $encryption;
72
73
    /**
74
     * If server has to validate cert.
75
     *
76
     * @var bool
77
     */
78
    public $validate_cert = true;
79
80
    /**
81
     * Proxy settings
82
     * @var array
83
     */
84
    protected $proxy = [
85
        'socket' => null,
86
        'request_fulluri' => false,
87
        'username' => null,
88
        'password' => null,
89
    ];
90
91
    /**
92
     * Account username/
93
     *
94
     * @var mixed
95
     */
96
    public $username;
97
98
    /**
99
     * Account password.
100
     *
101
     * @var string
102
     */
103
    public $password;
104
105
    /**
106
     * Account authentication method.
107
     *
108
     * @var string
109
     */
110
    public $authentication;
111
112
    /**
113
     * Active folder.
114
     *
115
     * @var Folder
116
     */
117
    protected $active_folder = false;
118
119
    /**
120
     * Default message mask
121
     *
122
     * @var string $default_message_mask
123
     */
124
    protected $default_message_mask = MessageMask::class;
125
126
    /**
127
     * Default attachment mask
128
     *
129
     * @var string $default_attachment_mask
130
     */
131
    protected $default_attachment_mask = AttachmentMask::class;
132
133
    /**
134
     * Used default account values
135
     *
136
     * @var array $default_account_config
137
     */
138
    protected $default_account_config = [
139
        'host' => 'localhost',
140
        'port' => 993,
141
        'protocol'  => 'imap',
142
        'encryption' => 'ssl',
143
        'validate_cert' => true,
144
        'username' => '',
145
        'password' => '',
146
        'authentication' => null,
147
        'proxy' => [
148
            'socket' => null,
149
            'request_fulluri' => false,
150
            'username' => null,
151
            'password' => null,
152
        ]
153
    ];
154
155
    /**
156
     * Client constructor.
157
     * @param array $config
158
     *
159
     * @throws MaskNotFoundException
160
     */
161
    public function __construct($config = []) {
162
        $this->setConfig($config);
163
        $this->setMaskFromConfig($config);
164
        $this->setEventsFromConfig($config);
165
    }
166
167
    /**
168
     * Client destructor
169
     */
170
    public function __destruct() {
171
        $this->disconnect();
172
    }
173
174
    /**
175
     * Set the Client configuration
176
     * @param array $config
177
     *
178
     * @return self
179
     */
180
    public function setConfig(array $config) {
181
        $default_account = ClientManager::get('default');
182
        $default_config  = ClientManager::get("accounts.$default_account");
183
184
        foreach ($this->default_account_config as $key => $value) {
185
            $this->setAccountConfig($key, $config, $default_config);
186
        }
187
188
        return $this;
189
    }
190
191
    /**
192
     * Set a specific account config
193
     * @param string $key
194
     * @param array $config
195
     * @param array $default_config
196
     */
197
    private function setAccountConfig($key, $config, $default_config){
198
        $value = $this->default_account_config[$key];
199
        if(isset($config[$key])) {
200
            $value = $config[$key];
201
        }elseif(isset($default_config[$key])) {
202
            $value = $default_config[$key];
203
        }
204
        $this->$key = $value;
205
    }
206
207
    /**
208
     * Look for a possible events in any available config
209
     * @param $config
210
     */
211
    protected function setEventsFromConfig($config) {
212
        $this->events = ClientManager::get("events");
213
        if(isset($config['events'])){
214
            if(isset($config['events'])) {
215
                foreach($config['events'] as $section => $events) {
216
                    $this->events[$section] = array_merge($this->events[$section], $events);
217
                }
218
            }
219
        }
220
    }
221
222
    /**
223
     * Look for a possible mask in any available config
224
     * @param $config
225
     *
226
     * @throws MaskNotFoundException
227
     */
228
    protected function setMaskFromConfig($config) {
229
        $default_config  = ClientManager::get("masks");
230
231
        if(isset($config['masks'])){
232
            if(isset($config['masks']['message'])) {
233
                if(class_exists($config['masks']['message'])) {
234
                    $this->default_message_mask = $config['masks']['message'];
235
                }else{
236
                    throw new MaskNotFoundException("Unknown mask provided: ".$config['masks']['message']);
237
                }
238
            }else{
239
                if(class_exists($default_config['message'])) {
240
                    $this->default_message_mask = $default_config['message'];
241
                }else{
242
                    throw new MaskNotFoundException("Unknown mask provided: ".$default_config['message']);
243
                }
244
            }
245
            if(isset($config['masks']['attachment'])) {
246
                if(class_exists($config['masks']['attachment'])) {
247
                    $this->default_message_mask = $config['masks']['attachment'];
248
                }else{
249
                    throw new MaskNotFoundException("Unknown mask provided: ".$config['masks']['attachment']);
250
                }
251
            }else{
252
                if(class_exists($default_config['attachment'])) {
253
                    $this->default_message_mask = $default_config['attachment'];
254
                }else{
255
                    throw new MaskNotFoundException("Unknown mask provided: ".$default_config['attachment']);
256
                }
257
            }
258
        }else{
259
            if(class_exists($default_config['message'])) {
260
                $this->default_message_mask = $default_config['message'];
261
            }else{
262
                throw new MaskNotFoundException("Unknown mask provided: ".$default_config['message']);
263
            }
264
265
            if(class_exists($default_config['attachment'])) {
266
                $this->default_message_mask = $default_config['attachment'];
267
            }else{
268
                throw new MaskNotFoundException("Unknown mask provided: ".$default_config['attachment']);
269
            }
270
        }
271
272
    }
273
274
    /**
275
     * Get the current imap resource
276
     *
277
     * @return bool|Protocol|ProtocolInterface
278
     * @throws ConnectionFailedException
279
     */
280
    public function getConnection() {
281
        $this->checkConnection();
282
        return $this->connection;
283
    }
284
285
    /**
286
     * Determine if connection was established.
287
     *
288
     * @return bool
289
     */
290
    public function isConnected() {
291
        return $this->connection ? $this->connection->connected() : false;
0 ignored issues
show
Bug introduced by
The method connected() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

291
        return $this->connection ? $this->connection->/** @scrutinizer ignore-call */ connected() : false;
Loading history...
Bug introduced by
The method connected() does not exist on Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. Did you maybe mean connect()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

291
        return $this->connection ? $this->connection->/** @scrutinizer ignore-call */ connected() : false;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
292
    }
293
294
    /**
295
     * Determine if connection was established and connect if not.
296
     *
297
     * @throws ConnectionFailedException
298
     */
299
    public function checkConnection() {
300
        if (!$this->isConnected()) {
301
            $this->connect();
302
        }
303
    }
304
305
    /**
306
     * Force a reconnect
307
     *
308
     * @throws ConnectionFailedException
309
     */
310
    public function reconnect() {
311
        if ($this->isConnected()) {
312
            $this->disconnect();
313
        }
314
        $this->connect();
315
    }
316
317
    /**
318
     * Connect to server.
319
     *
320
     * @return $this
321
     * @throws ConnectionFailedException
322
     */
323
    public function connect() {
324
        $this->disconnect();
325
        $protocol = strtolower($this->protocol);
326
327
        if ($protocol == "imap") {
328
            $timeout = $this->connection !== false ? $this->connection->getConnectionTimeout() : null;
0 ignored issues
show
Bug introduced by
The method getConnectionTimeout() does not exist on Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

328
            $timeout = $this->connection !== false ? $this->connection->/** @scrutinizer ignore-call */ getConnectionTimeout() : null;
Loading history...
329
            $this->connection = new ImapProtocol($this->validate_cert, $this->encryption);
330
            $this->connection->setConnectionTimeout($timeout);
331
            $this->connection->setProxy($this->proxy);
332
        }else{
333
            if (extension_loaded('imap') === false) {
334
                throw new ConnectionFailedException("connection setup failed", 0, new ProtocolNotSupportedException($protocol." is an unsupported protocol"));
335
            }
336
            $this->connection = new LegacyProtocol($this->validate_cert, $this->encryption);
337
            if (strpos($protocol, "legacy-") === 0) {
338
                $protocol = substr($protocol, 7);
339
            }
340
            $this->connection->setProtocol($protocol);
341
        }
342
343
        try {
344
            $this->connection->connect($this->host, $this->port);
345
        } catch (\ErrorException $e) {
346
            throw new ConnectionFailedException("connection setup failed", 0, $e);
347
        } catch (Exceptions\RuntimeException $e) {
348
            throw new ConnectionFailedException("connection setup failed", 0, $e);
349
        }
350
        $this->authenticate();
351
352
        return $this;
353
    }
354
355
    /**
356
     * Authenticate the current session
357
     *
358
     * @throws ConnectionFailedException
359
     */
360
    protected function authenticate() {
361
        try {
362
            if ($this->authentication == "oauth") {
363
                if (!$this->connection->authenticate($this->username, $this->password)) {
0 ignored issues
show
Bug introduced by
The method authenticate() does not exist on Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

363
                if (!$this->connection->/** @scrutinizer ignore-call */ authenticate($this->username, $this->password)) {
Loading history...
Bug introduced by
The method authenticate() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

363
                if (!$this->connection->/** @scrutinizer ignore-call */ authenticate($this->username, $this->password)) {
Loading history...
364
                    throw new AuthFailedException();
365
                }
366
            } elseif (!$this->connection->login($this->username, $this->password)) {
0 ignored issues
show
Bug introduced by
The method login() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

366
            } elseif (!$this->connection->/** @scrutinizer ignore-call */ login($this->username, $this->password)) {
Loading history...
367
                throw new AuthFailedException();
368
            }
369
        } catch (\Exception $e) {
370
            throw new ConnectionFailedException("connection setup failed", 0, $e);
371
        }
372
    }
373
374
    /**
375
     * Disconnect from server.
376
     *
377
     * @return $this
378
     */
379
    public function disconnect() {
380
        if ($this->isConnected() && $this->connection !== false) {
381
            $this->connection->logout();
0 ignored issues
show
Bug introduced by
The method logout() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

381
            $this->connection->/** @scrutinizer ignore-call */ 
382
                               logout();
Loading history...
382
        }
383
        $this->active_folder = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type Webklex\PHPIMAP\Folder of property $active_folder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
384
385
        return $this;
386
    }
387
388
    /**
389
     * Get a folder instance by a folder name
390
     * @param string $folder_name
391
     * @param string|bool $delimiter
392
     *
393
     * @return mixed
394
     * @throws ConnectionFailedException
395
     * @throws FolderFetchingException
396
     * @throws Exceptions\RuntimeException
397
     */
398
    public function getFolder($folder_name, $delimiter = null) {
399
        // Set delimiter to false to force selection via getFolderByName (maybe useful for uncommon folder names)
400
        if ($delimiter !== false) {
401
            $delimiter = (is_null($delimiter)) ? ClientManager::get('options.delimiter', "/") : $delimiter;
0 ignored issues
show
introduced by
The condition is_null($delimiter) is always false.
Loading history...
402
            if (strpos($folder_name, $delimiter) !== false) {
403
                return $this->getFolderByPath($folder_name);
404
            }
405
	    }
406
407
        return $this->getFolderByName($folder_name);
408
    }
409
410
    /**
411
     * Get a folder instance by a folder name
412
     * @param $folder_name
413
     *
414
     * @return mixed
415
     * @throws ConnectionFailedException
416
     * @throws FolderFetchingException
417
     * @throws Exceptions\RuntimeException
418
     */
419
    public function getFolderByName($folder_name) {
420
        return $this->getFolders(false)->where("name", $folder_name)->first();
421
    }
422
423
    /**
424
     * Get a folder instance by a folder path
425
     * @param $folder_path
426
     *
427
     * @return mixed
428
     * @throws ConnectionFailedException
429
     * @throws FolderFetchingException
430
     * @throws Exceptions\RuntimeException
431
     */
432
    public function getFolderByPath($folder_path) {
433
        return $this->getFolders(false)->where("path", $folder_path)->first();
434
    }
435
436
    /**
437
     * Get folders list.
438
     * If hierarchical order is set to true, it will make a tree of folders, otherwise it will return flat array.
439
     *
440
     * @param boolean $hierarchical
441
     * @param string|null $parent_folder
442
     *
443
     * @return FolderCollection
444
     * @throws ConnectionFailedException
445
     * @throws FolderFetchingException
446
     * @throws Exceptions\RuntimeException
447
     */
448
    public function getFolders($hierarchical = true, $parent_folder = null) {
449
        $this->checkConnection();
450
        $folders = FolderCollection::make([]);
451
452
        $pattern = $parent_folder.($hierarchical ? '%' : '*');
453
        $items = $this->connection->folders('', $pattern);
0 ignored issues
show
Bug introduced by
The method folders() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

453
        /** @scrutinizer ignore-call */ 
454
        $items = $this->connection->folders('', $pattern);
Loading history...
454
455
        if(is_array($items)){
0 ignored issues
show
introduced by
The condition is_array($items) is always true.
Loading history...
456
            foreach ($items as $folder_name => $item) {
457
                $folder = new Folder($this, $folder_name, $item["delimiter"], $item["flags"]);
458
459
                if ($hierarchical && $folder->hasChildren()) {
460
                    $pattern = $folder->full_name.$folder->delimiter.'%';
461
462
                    $children = $this->getFolders(true, $pattern);
463
                    $folder->setChildren($children);
464
                }
465
466
                $folders->push($folder);
467
            }
468
469
            return $folders;
470
        }else{
471
            throw new FolderFetchingException("failed to fetch any folders");
472
        }
473
    }
474
475
    /**
476
     * Open folder.
477
     * @param string $folder
478
     * @param boolean $force_select
479
     *
480
     * @return mixed
481
     * @throws ConnectionFailedException
482
     * @throws Exceptions\RuntimeException
483
     */
484
    public function openFolder($folder, $force_select = false) {
485
        if ($this->active_folder == $folder && $this->isConnected() && $force_select === false) {
0 ignored issues
show
introduced by
The condition $this->active_folder == $folder is always false.
Loading history...
486
            return true;
487
        }
488
        $this->checkConnection();
489
        $this->active_folder = $folder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $folder of type string is incompatible with the declared type Webklex\PHPIMAP\Folder of property $active_folder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
490
        return $this->connection->selectFolder($folder);
0 ignored issues
show
Bug introduced by
The method selectFolder() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

490
        return $this->connection->/** @scrutinizer ignore-call */ selectFolder($folder);
Loading history...
491
    }
492
493
    /**
494
     * Create a new Folder
495
     * @param string $folder
496
     * @param boolean $expunge
497
     *
498
     * @return bool
499
     * @throws ConnectionFailedException
500
     * @throws FolderFetchingException
501
     * @throws Exceptions\EventNotFoundException
502
     * @throws Exceptions\RuntimeException
503
     */
504
    public function createFolder($folder, $expunge = true) {
505
        $this->checkConnection();
506
        $status = $this->connection->createFolder($folder);
0 ignored issues
show
Bug introduced by
The method createFolder() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

506
        /** @scrutinizer ignore-call */ 
507
        $status = $this->connection->createFolder($folder);
Loading history...
507
508
        if($expunge) $this->expunge();
509
510
        $folder = $this->getFolder($folder);
511
        if($status && $folder) {
512
            $event = $this->getEvent("folder", "new");
513
            $event::dispatch($folder);
514
        }
515
516
        return $folder;
517
    }
518
519
    /**
520
     * Check a given folder
521
     * @param $folder
522
     *
523
     * @return false|object
524
     * @throws ConnectionFailedException
525
     * @throws Exceptions\RuntimeException
526
     */
527
    public function checkFolder($folder) {
528
        $this->checkConnection();
529
        return $this->connection->examineFolder($folder);
0 ignored issues
show
Bug introduced by
The method examineFolder() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

529
        return $this->connection->/** @scrutinizer ignore-call */ examineFolder($folder);
Loading history...
Bug Best Practice introduced by
The expression return $this->connection->examineFolder($folder) returns the type array|boolean which is incompatible with the documented return type false|object.
Loading history...
530
    }
531
532
    /**
533
     * Get the current active folder
534
     *
535
     * @return Folder
536
     */
537
    public function getFolderPath(){
538
        return $this->active_folder;
539
    }
540
541
    /**
542
     * Retrieve the quota level settings, and usage statics per mailbox
543
     *
544
     * @return array
545
     * @throws ConnectionFailedException
546
     * @throws Exceptions\RuntimeException
547
     */
548
    public function getQuota() {
549
        $this->checkConnection();
550
        return $this->connection->getQuota($this->username);
0 ignored issues
show
Bug introduced by
The method getQuota() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

550
        return $this->connection->/** @scrutinizer ignore-call */ getQuota($this->username);
Loading history...
551
    }
552
553
    /**
554
     * Retrieve the quota settings per user
555
     * @param string $quota_root
556
     *
557
     * @return array
558
     * @throws ConnectionFailedException
559
     */
560
    public function getQuotaRoot($quota_root = 'INBOX') {
561
        $this->checkConnection();
562
        return $this->connection->getQuotaRoot($quota_root);
0 ignored issues
show
Bug introduced by
The method getQuotaRoot() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

562
        return $this->connection->/** @scrutinizer ignore-call */ getQuotaRoot($quota_root);
Loading history...
563
    }
564
565
    /**
566
     * Delete all messages marked for deletion
567
     *
568
     * @return bool
569
     * @throws ConnectionFailedException
570
     * @throws Exceptions\RuntimeException
571
     */
572
    public function expunge() {
573
        $this->checkConnection();
574
        return $this->connection->expunge();
0 ignored issues
show
Bug introduced by
The method expunge() does not exist on Webklex\PHPIMAP\Connection\Protocols\Protocol. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connection\Protocols\Protocol. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

574
        return $this->connection->/** @scrutinizer ignore-call */ expunge();
Loading history...
575
    }
576
577
    /**
578
     * Set the imap timeout for a given operation type
579
     * @param $timeout
580
     *
581
     * @return Protocol
582
     */
583
    public function setTimeout($timeout) {
584
        return $this->connection->setConnectionTimeout($timeout);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->connection...ectionTimeout($timeout) also could return the type Webklex\PHPIMAP\Connecti...otocolInterface|boolean which is incompatible with the documented return type Webklex\PHPIMAP\Connection\Protocols\Protocol.
Loading history...
Bug introduced by
The method setConnectionTimeout() does not exist on Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Webklex\PHPIMAP\Connecti...ocols\ProtocolInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

584
        return $this->connection->/** @scrutinizer ignore-call */ setConnectionTimeout($timeout);
Loading history...
585
    }
586
587
    /**
588
     * Get the timeout for a certain operation
589
     * @param $type
590
     *
591
     * @return int
592
     */
593
    public function getTimeout($type){
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

593
    public function getTimeout(/** @scrutinizer ignore-unused */ $type){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
594
        return $this->connection->getConnectionTimeout();
595
    }
596
597
    /**
598
     * Get the default message mask
599
     *
600
     * @return string
601
     */
602
    public function getDefaultMessageMask(){
603
        return $this->default_message_mask;
604
    }
605
606
    /**
607
     * Get the default events for a given section
608
     * @param $section
609
     *
610
     * @return array
611
     */
612
    public function getDefaultEvents($section){
613
        return $this->events[$section];
614
    }
615
616
    /**
617
     * Set the default message mask
618
     * @param $mask
619
     *
620
     * @return $this
621
     * @throws MaskNotFoundException
622
     */
623
    public function setDefaultMessageMask($mask) {
624
        if(class_exists($mask)) {
625
            $this->default_message_mask = $mask;
626
627
            return $this;
628
        }
629
630
        throw new MaskNotFoundException("Unknown mask provided: ".$mask);
631
    }
632
633
    /**
634
     * Get the default attachment mask
635
     *
636
     * @return string
637
     */
638
    public function getDefaultAttachmentMask(){
639
        return $this->default_attachment_mask;
640
    }
641
642
    /**
643
     * Set the default attachment mask
644
     * @param $mask
645
     *
646
     * @return $this
647
     * @throws MaskNotFoundException
648
     */
649
    public function setDefaultAttachmentMask($mask) {
650
        if(class_exists($mask)) {
651
            $this->default_attachment_mask = $mask;
652
653
            return $this;
654
        }
655
656
        throw new MaskNotFoundException("Unknown mask provided: ".$mask);
657
    }
658
}
659