EmailTarget   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 33
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A export() 0 13 2
1
<?php
2
/**
3
 * Health monitoring for Yii2 applications
4
 *
5
 * @link      https://github.com/hiqdev/yii2-monitoring
6
 * @package   yii2-monitoring
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\monitoring\targets;
12
13
use hiqdev\yii2\monitoring\Module;
14
use yii\mail\MailerInterface;
15
16
class EmailTarget extends \yii\log\Target
17
{
18
    public $view;
19
20
    public $from;
21
    public $to;
22
    public $subject;
23
24
    /**
25
     * @var MailerInterface
26
     */
27
    private $mailer;
28
29
    public function __construct(MailerInterface $mailer, $options = [])
30
    {
31
        parent::__construct($options);
32
        $this->mailer = $mailer;
33
    }
34
35
    public function export()
36
    {
37
        $module = Module::getInstance();
38
39
        foreach ($this->messages as $message) {
40
            return $this->mailer
41
                ->compose($this->view, $module->prepareMessageData($message, $this))
42
                ->setTo($this->to)
43
                ->setFrom($module->flagEmail($this->from))
44
                ->setSubject($module->prepareSubject($message, $this->subject))
45
                ->send();
46
        }
47
    }
48
}
49