FixListener::__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\ClubinfoBundle\Listener;
4
5
use Doctrine\ORM\Event\LifecycleEventArgs;
6
use KI\ClubinfoBundle\Entity\Fix;
7
use KI\ClubinfoBundle\Service\SlackService;
8
use KI\UserBundle\Entity\Achievement;
9
use KI\UserBundle\Event\AchievementCheckEvent;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
12
class FixListener
13
{
14
    protected $slackService;
15
    protected $dispatcher;
16
17
    public function __construct(SlackService $slackService, EventDispatcherInterface $dispatcher)
18
    {
19
        $this->slackService = $slackService;
20
        $this->dispatcher   = $dispatcher;
21
    }
22
23
    public function postPersist(LifecycleEventArgs $args)
24
    {
25
        $entity = $args->getEntity();
26
27
        if ($entity instanceOf Fix) {
28
            // On poste sur Slack
29
            $this->slackService->post(
30
                $entity->getUser(),
31
                $entity->getFix() ? '#depannage' : '#upont-feedback',
32
                $entity->getProblem()
33
            );
34
35
            // On regarde les achievements
36 View Code Duplication
            if ($entity->getFix()) {
37
                $achievementCheck = new AchievementCheckEvent(Achievement::BUG_CONTACT);
38
                $this->dispatcher->dispatch('upont.achievement', $achievementCheck);
39
            } else {
40
                $achievementCheck = new AchievementCheckEvent(Achievement::BUG_REPORT);
41
                $this->dispatcher->dispatch('upont.achievement', $achievementCheck);
42
            }
43
        }
44
    }
45
}
46