Test Setup Failed
Push — develop ( 82cf6b...198473 )
by Stone
06:50 queued 11s
created

RegistrationMailer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendHash() 0 13 1
1
<?php
2
3
namespace App\Services\Registration;
4
5
use App\Entity\User;
6
use Symfony\Component\Templating\EngineInterface;
7
8
9
class RegistrationMailer
10
{
11
    /**
12
     * @var \Swift_Mailer
13
     */
14
    private $mailer;
15
    /**
16
     * @var EngineInterface
17
     */
18
    private $templating;
19
    private $adminEmail;
20
21
    public function __construct($adminEmail, \Swift_Mailer $mailer, EngineInterface $templating)
22
    {
23
        $this->mailer = $mailer;
24
        $this->templating = $templating;
25
        $this->adminEmail = $adminEmail;
26
    }
27
28
    /**
29
     * Send the hash link to the user
30
     * @param User $user
31
     * @return int The number of successful recipients. Can be 0 which indicates failure
32
     */
33
    public function sendHash(User $user): int
34
    {
35
        $message = (new \Swift_Message('Email validation'))
36
            ->setFrom($this->adminEmail)
37
            ->setTo($user->getEmail())
38
            ->setBody(
39
                $this->templating->render(
40
                    'emails/hash.html.twig',
41
                    ['user' => $user]
42
                ),
43
                'text/html'
44
            );
45
        return $this->mailer->send($message);
46
    }
47
}