Completed
Branch develop (b9c805)
by Pavel
06:33
created

MailerService::sendMail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
ccs 0
cts 14
cp 0
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: device
5
 * Date: 19.03.16
6
 * Time: 10:05
7
 */
8
9
namespace AppBundle\Services;
10
11
12
use Symfony\Bundle\TwigBundle\TwigEngine;
13
14
class MailerService
15
{
16
    private $mailer;
17
    private $templating;
18
19 1
    public function __construct(\Swift_Mailer $mailer, TwigEngine $template)
20
    {
21 1
        $this->mailer = $mailer;
22 1
        $this->templating = $template;
23 1
    }
24
25
    public function sendMail($mailTo)
26
    {
27
        $hash = md5(uniqid());
28
        $message = \Swift_Message::newInstance()
29
            ->setSubject('Registration')
30
            ->setFrom('[email protected]')
31
            ->setTo($mailTo)
32
            ->setBody(
33
                $this->templating->render(
34
                    '@App/Emails/registration.html.twig',
35
                    array('hash' => $hash, 'email' => $mailTo)
36
                ),
37
                'text/html'
38
            );
39
40
        $this->mailer->send($message);
41
42
        return $hash;
43
    }
44
}