Completed
Pull Request — master (#33)
by Pavel
03:21
created

MailerService::sendMailRecovery()   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
    private $generator;
19
    private $mailerFrom;
20
21 1
    public function __construct(\Swift_Mailer $mailer, TwigEngine $template, RandomGenerator $randomGenerator, $mailerFrom)
22
    {
23 1
        $this->mailer = $mailer;
24 1
        $this->templating = $template;
25 1
        $this->generator = $randomGenerator;
26 1
        $this->mailerFrom = $mailerFrom;
27 1
    }
28
29
    public function sendMail($mailTo)
30
    {
31
        $hash = md5(uniqid());
32
        $message = \Swift_Message::newInstance()
33
            ->setSubject('Registration')
34
            ->setFrom($this->mailerFrom)
35
            ->setTo($mailTo)
36
            ->setBody(
37
                $this->templating->render(
38
                    '@App/Emails/registration.html.twig',
39
                    array('hash' => $hash, 'email' => $mailTo)
40
                ),
41
                'text/html'
42
            );
43
44
        $this->mailer->send($message);
45
46
        return $hash;
47
    }
48
49
    public function sendMailRecovery($mailTo)
50
    {
51
        $password = $this->generator->generator();
52
        $message = \Swift_Message::newInstance()
53
            ->setSubject('Registration')
54
            ->setFrom($this->mailerFrom)
55
            ->setTo($mailTo)
56
            ->setBody(
57
                $this->templating->render(
58
                    '@App/Emails/recovery.html.twig',
59
                    array('password' => $password)
60
                ),
61
                'text/html'
62
            );
63
64
        $this->mailer->send($message);
65
66
        return $password;
67
    }
68
}