SendMailNegativeBalanceListener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendMail() 0 14 1
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