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

MailerService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 22.22%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 31
ccs 4
cts 18
cp 0.2222
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendMail() 0 19 1
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
}