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

Mailer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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