Passed
Push — master ( 2cbf33...efd300 )
by Viktor
01:36
created

Message::queue()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 3
nop 1
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 5
rs 8.8571
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 2
    public function queue(Mailer $mailer = null)
34
    {
35 2
        if ($mailer === null && $this->mailer === null) {
36 1
            $mailer = Yii::$app->getMailer();
37 1
        } elseif ($mailer === null) {
38 1
            $mailer = $this->mailer;
39
        }
40 2
        if (!$mailer instanceof Mailer) {
41 1
            throw new InvalidConfigException('The mailer should be an instance of "\izumi\spoolmailer\Mailer".');
42
        }
43 1
        return $mailer->queue($this);
44
    }
45
}
46