Completed
Push — master ( 88df08...39f418 )
by Alexey
40:05
created

MailQueueCommand::worker()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 4
nop 0
1
<?php
2
3
namespace yiicod\mailqueue\commands;
4
5
use Exception;
6
use Yii;
7
use yiicod\base\helpers\LoggerMessage;
8
use yiicod\cron\commands\DaemonController;
9
use yiicod\mailqueue\components\MailHandler;
10
use yiicod\mailqueue\components\MailHandlerInterface;
11
use yiicod\mailqueue\MailQueue;
12
13
/**
14
 * Console command
15
 * class MailQueueCommand
16
 */
17
class MailQueueCommand extends DaemonController
18
{
19
    /**
20
     * @var MailHandlerInterface
21
     */
22
    public $mailProvider = MailHandler::class;
23
24
    /**
25
     * Only one command can run in the same time in {n} times
26
     *
27
     * @param int $timeLock
28
     */
29
    public $timeLock = 3600;
30
31
    /**
32
     * Daemon name
33
     *
34
     * @return string
35
     */
36
    protected function daemonName(): string
37
    {
38
        return 'mail-queue';
39
    }
40
41
    /**
42
     * Run send mail
43
     */
44
    public function worker()
45
    {
46
        try {
47
            Yii::$app->db->close();
48
            Yii::$app->db->open();
49
            MailQueue::delivery(new $this->mailProvider());
50
        } catch (Exception $e) {
51
            Yii::error(LoggerMessage::log($e), __METHOD__);
0 ignored issues
show
Documentation introduced by
$e is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
        }
53
    }
54
}
55