FixListener   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 20.59 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A postPersist() 7 22 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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