SendMailNegativeBalanceListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace KI\FoyerBundle\Listener;
4
5
use KI\FoyerBundle\Event\UserNegativeBalanceEvent;
6
use Swift_Mailer;
7
use Swift_Message;
8
use Symfony\Bundle\TwigBundle\TwigEngine;
9
10
class SendMailNegativeBalanceListener
11
{
12
    private $swiftMailer;
13
    private $twigEngine;
14
15
    public function __construct(Swift_Mailer $swiftMailer, TwigEngine $twigEngine)
16
    {
17
        $this->swiftMailer = $swiftMailer;
18
        $this->twigEngine = $twigEngine;
19
    }
20
21
    // Check si un achievement donné est accompli, si oui envoie une notification
22
    public function sendMail(UserNegativeBalanceEvent $event)
23
    {
24
        $user = $event->getUser();
25
26
        $message = Swift_Message::newInstance()
27
            ->setSubject('Pense à recharger ton compte foyer !')
28
            ->setFrom('[email protected]')
29
            ->setTo($user->getEmail())
30
            ->setBody($this->twigEngine->render('KIFoyerBundle::negative-balance.html.twig', [
31
                'user' => $user
32
            ]), 'text/html');
33
34
        $this->swiftMailer->send($message);
35
    }
36
}
37