Completed
Pull Request — master (#2737)
by
unknown
08:55
created

PasswordMailerService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A sendPasswordForgotMail() 0 18 1
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Service;
4
5
use Kunstmaan\AdminBundle\Entity\UserInterface;
6
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
7
use Symfony\Component\Routing\RouterInterface;
8
use Symfony\Contracts\Translation\TranslatorInterface;
9
use Symfony\Component\Mailer\MailerInterface;
10
use Symfony\Component\Mime\Address;
11
12
class PasswordMailerService implements PasswordMailerInterface
13
{
14
    /** @var MailerInterface */
15
    private $mailer;
16
17
    /** @var RouterInterface */
18
    private $router;
19
20
    /** @var Address */
21
    private $from;
22
23
    /** @var TranslatorInterface */
24
    private $translator;
25
26
    public function __construct(MailerInterface $mailer, RouterInterface $router, TranslatorInterface $translator, Address $from)
27
    {
28
        $this->mailer = $mailer;
29
        $this->router = $router;
30
        $this->translator = $translator;
31
        $this->from = $from;
32
    }
33
34
    public function sendPasswordForgotMail(UserInterface $user, string $locale)
35
    {
36
        $to = $user->getEmail();
37
        $confirmationUrl = $this->router->generate('cms_reset_password_confirm', ['token' => $user->getConfirmationToken()], RouterInterface::ABSOLUTE_URL);
38
        $subject = $this->translator->trans('Password reset email', [], null, $locale);
39
40
        $email = (new TemplatedEmail())
41
            ->from($this->from)
42
            ->to($to)
43
            ->subject($subject)
44
            ->htmlTemplate('@KunstmaanAdmin/Resetting/email.txt.twig')
45
            ->context([
46
                'user' => $user,
47
                'confirmationUrl' => $confirmationUrl,
48
            ]);
49
50
        $this->mailer->send($email);
51
    }
52
}
53