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

RegistrationMailer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
}