Passed
Push — master ( 786b21...4a8f5f )
by Stone
06:47 queued 42s
created

SendMail   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 17 2
A __construct() 0 4 1
1
<?php
2
3
namespace App\Mail;
4
5
use Symfony\Component\Templating\EngineInterface;
6
7
class SendMail
8
{
9
10
    /**
11
     * @var \Swift_Mailer
12
     */
13
    private $mailer;
14
    /**
15
     * @var EngineInterface
16
     */
17
    private $templating;
18
19
    public function __construct(\Swift_Mailer $mailer, EngineInterface $templating)
20
    {
21
        $this->mailer = $mailer;
22
        $this->templating = $templating;
23
    }
24
25
    public function send(string $subject, string $template, $mailData, string $to, String $from = null):bool
26
    {
27
        if ($from === null){
28
            $from = getenv('ADMIN_EMAIL');
29
        }
30
31
        $message = (new \Swift_Message($subject))
32
            ->setFrom($from)
33
            ->setTo($to)
34
            ->setBody(
35
                $this->templating->render(
36
                    $template,
37
                    ['mailData' => $mailData]
38
                ),
39
                'text/html'
40
            );
41
        return $this->mailer->send($message)>0;
42
43
    }
44
45
}