Completed
Push — master ( e69be6...7cd7bd )
by Wilmer
01:37
created

Mailer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sendMessage() 0 9 1
1
<?php
2
3
namespace terabytesoft\helpers;
4
5
use yii\base\Component;
6
7
/**
8
 * Class Mailer
9
 *
10
 **/
11
class Mailer extends Component
12
{
13
    /**
14
     * @var object $mailer
15
     */
16
    private $mailer;
17
18
19
    /**
20
     * __construct
21
     */
22 1
    public function __construct(object $mailer)
23
    {
24 1
        $this->mailer = $mailer;
25 1
        $this->mailer->viewPath = \Yii::$app->params['helper.mailer.viewpath'];
26 1
    }
27
28
    /**
29
     * sendMessage
30
     */
31 1
    public function sendMessage(string $to, string $subject, string $view, array $params = []): bool
32
    {
33 1
        return $this->mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)
34 1
            ->setTo($to)
35 1
            ->setFrom(
36 1
                [\Yii::$app->params['helper.mailer.sender'] => \Yii::$app->params['helper.mailer.sender.name']]
37
            )
38 1
            ->setSubject($subject)
39 1
            ->send();
40
    }
41
}
42