FlashService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 19.75 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 16
loc 81
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A mergeSuccessMessages() 8 8 1
A mergeErrorMessages() 8 8 1
A mergeFlashMessages() 0 8 1
A retrieveSuccessMessages() 0 4 1
A retrieveErrorMessages() 0 4 1
A retrieveFlashMessages() 0 4 1

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 Foo\Session;
4
5
use Opulence\Sessions\ISession;
6
7
class FlashService
8
{
9
    const ERROR   = 'error';
10
    const SUCCESS = 'success';
11
12
    /** @var ISession */
13
    protected $session;
14
15
    /**
16
     * Helper constructor.
17
     *
18
     * @param ISession $session
19
     */
20 7
    public function __construct(ISession $session)
21
    {
22 7
        $this->session = $session;
23 7
    }
24
25
    /**
26
     * @param string[] $value
27
     */
28 1 View Code Duplication
    public function mergeSuccessMessages(array $value)
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...
29
    {
30 1
        $currentValue = (array)$this->session->get(static::SUCCESS);
31
32 1
        $newValue = array_merge($currentValue, $value);
33
34 1
        $this->session->flash(static::SUCCESS, $newValue);
35 1
    }
36
37
    /**
38
     * @param string[] $value
39
     */
40 1 View Code Duplication
    public function mergeErrorMessages(array $value)
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...
41
    {
42 1
        $currentValue = (array)$this->session->get(static::ERROR);
43
44 1
        $newValue = array_merge($currentValue, $value);
45
46 1
        $this->session->flash(static::ERROR, $newValue);
47 1
    }
48
49
    /**
50
     * @param string   $key
51
     * @param string[] $value
52
     */
53 1
    public function mergeFlashMessages(string $key, array $value)
54
    {
55 1
        $currentValue = (array)$this->session->get($key);
56
57 1
        $newValue = array_merge($currentValue, $value);
58
59 1
        $this->session->flash($key, $newValue);
60 1
    }
61
62
    /**
63
     * @return array
64
     */
65 1
    public function retrieveSuccessMessages()
66
    {
67 1
        return (array)$this->session->get(static::SUCCESS);
68
    }
69
70
    /**
71
     * @return array
72
     */
73 1
    public function retrieveErrorMessages()
74
    {
75 1
        return (array)$this->session->get(static::ERROR);
76
    }
77
78
    /**
79
     * @param string $key
80
     *
81
     * @return array
82
     */
83 1
    public function retrieveFlashMessages(string $key)
84
    {
85 1
        return (array)$this->session->get($key);
86
    }
87
}
88
89