Message::queue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://github.com/Izumi-kun/yii2-spoolmailer
4
 * @copyright Copyright (c) 2017 Viktor Khokhryakov
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace izumi\spoolmailer;
9
10
use Yii;
11
use yii\base\InvalidConfigException;
12
13
/**
14
 * Extends `yii\swiftmailer\Message` to enable queuing.
15
 *
16
 * @author Viktor Khokhryakov <[email protected]>
17
 */
18
class Message extends \yii\swiftmailer\Message
19
{
20
    /**
21
     * @var Mailer the mailer instance that created this message.
22
     */
23
    public $mailer;
24
25
    /**
26
     * Enqueue this email message.
27
     * @param Mailer $mailer the mailer that should be used to queue this message.
28
     * If no mailer is given it will first check if "mailer" property is set and if not,
29
     * the "mail" application component will be used instead.
30
     * @return bool whether this message is added to queue successfully.
31
     * @throws InvalidConfigException
32
     */
33 4
    public function queue(Mailer $mailer = null)
34
    {
35 4
        $mailer = $mailer ?? $this->mailer ?? Yii::$app->getMailer();
36 4
        if (!$mailer instanceof Mailer) {
37 1
            throw new InvalidConfigException('The mailer should be an instance of "\izumi\spoolmailer\Mailer".');
38
        }
39
40 3
        return $mailer->queue($this);
41
    }
42
}
43