Completed
Push — master ( 858bee...ca95b0 )
by Pavel
10s
created

MailerService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 17.14%

Importance

Changes 5
Bugs 2 Features 3
Metric Value
wmc 3
c 5
b 2
f 3
lcom 1
cbo 5
dl 0
loc 99
ccs 6
cts 35
cp 0.1714
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A sendMail() 0 19 1
A sendMailCheckWithRecovery() 0 20 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
    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)
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
    {
51
        $password = $this->generator->generator();
52
        $message = \Swift_Message::newInstance()
53
            ->setSubject('Recovery')
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
69
    public function sendMailCheckRecovery($mailTo)
70
    {
71
        $hash = md5(uniqid());
72
        $message = \Swift_Message::newInstance()
73
            ->setSubject('Recovery password')
74
            ->setFrom($this->mailerFrom)
75
            ->setTo($mailTo)
76
            ->setBody(
77
                $this->templating->render(
78
                    '@App/Emails/checkRecovery.html.twig',
79
                    ['hash' => $hash]
80
                ),
81
                'text/html'
82
            );
83
84
        $this->mailer->send($message);
85
86
        return $hash;
87
    }*/
88
89
90
    public function sendMailCheckWithRecovery($mailTo)
91
    {
92
        $hash = md5(uniqid());
93
        $password = $this->generator->generator();
94
        $message = \Swift_Message::newInstance()
95
            ->setSubject('Recovery password')
96
            ->setFrom($this->mailerFrom)
97
            ->setTo($mailTo)
98
            ->setBody(
99
                $this->templating->render(
100
                    '@App/Emails/checkWithRecovery.html.twig',
101
                    ['hash' => $hash, 'password' => $password]
102
                ),
103
                'text/html'
104
            );
105
106
        $this->mailer->send($message);
107
108
        return [$password, $hash];
109
    }
110
111
112
}