Passed
Push — master ( 284e20...561362 )
by Viktor
01:47
created

MailController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionFlush() 0 3 1
A beforeAction() 0 8 2
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\console\Controller;
11
use yii\di\Instance;
12
13
/**
14
 * MailController
15
 *
16
 * @author Viktor Khokhryakov <[email protected]>
17
 */
18
class MailController extends Controller
19
{
20
    public $defaultAction = 'flush';
21
    /**
22
     * @var Mailer|array|string the mailer object or the application component ID of the mailer object.
23
     */
24
    public $mailer = 'mailer';
25
26
    /**
27
     * @inheritdoc
28
     */
29 1
    public function beforeAction($action)
30
    {
31 1
        if (!parent::beforeAction($action)) {
32
            return false;
33
        }
34 1
        $this->mailer = Instance::ensure($this->mailer, Mailer::class);
35
36 1
        return true;
37
    }
38
39
    /**
40
     * Sends messages.
41
     */
42 1
    public function actionFlush()
43
    {
44 1
        $this->mailer->flushQueue();
45 1
    }
46
}
47