Completed
Pull Request — master (#90)
by Arnaud
19:08
created

MessageHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 35.62 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 26
loc 73
ccs 21
cts 21
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handleError() 13 13 2
A handleSuccess() 13 13 2

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 LAG\AdminBundle\Message;
4
5
use Psr\Log\LoggerInterface;
6
use Symfony\Component\HttpFoundation\Session\Session;
7
use Symfony\Component\Translation\TranslatorInterface;
8
9
class MessageHandler implements MessageHandlerInterface
10
{
11
    /**
12
     * @var LoggerInterface
13
     */
14
    protected $logger;
15
16
    /**
17
     * @var Session
18
     */
19
    protected $session;
20
21
    /**
22
     * @var TranslatorInterface
23
     */
24
    protected $translator;
25
26
    /**
27
     * ErrorHandler constructor
28
     *
29
     * @param LoggerInterface $logger
30
     * @param Session $session
31
     * @param TranslatorInterface $translator
32
     */
33 2
    public function __construct(LoggerInterface $logger, Session $session, TranslatorInterface $translator)
34
    {
35 2
        $this->logger = $logger;
36 2
        $this->session = $session;
37 2
        $this->translator = $translator;
38 2
    }
39
40
    /**
41
     * Create an flash message into the session. It will be translated. If $logMessage is defined, it will be logged
42
     * using the logger using the error channel
43
     *
44
     * @param string $flashMessage
45
     * @param string|null $logMessage
46
     */
47 1 View Code Duplication
    public function handleError($flashMessage, $logMessage = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $this
50 1
            ->session
51 1
            ->getFlashBag()
52 1
            ->add('error', $this->translator->trans($flashMessage));
53
54 1
        if ($logMessage) {
55
            $this
56 1
                ->logger
57 1
                ->error($logMessage);
58
        }
59 1
    }
60
61
    /**
62
     * Create an flash message into the session. It will be translated. If $logMessage is defined, it will be logged
63
     * using the logger using info channel
64
     *
65
     * @param $flashMessage
66
     * @param null $logMessage
67
     */
68 1 View Code Duplication
    public function handleSuccess($flashMessage, $logMessage = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $this
71 1
            ->session
72 1
            ->getFlashBag()
73 1
            ->add('info', $this->translator->trans($flashMessage));
74
75 1
        if ($logMessage) {
76
            $this
77 1
                ->logger
78 1
                ->info($logMessage);
79
        }
80 1
    }
81
}
82