FlashService::retrieveSuccessMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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