Completed
Pull Request — master (#50)
by devosc
03:02
created

Messages::message()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 *
4
 */
5
6
namespace Mvc5\Session\Config;
7
8
use Mvc5\Arg;
9
use Mvc5\Config\Config;
10
11
trait Messages
12
{
13
    /**
14
     *
15
     */
16
    use Config;
17
18
    /**
19
     * @var array
20
     */
21
    protected $new = [];
22
23
    /**
24
     * @param string|array $message
25
     * @param string $name
26
     * @param string $type
27
     * @return array
28
     */
29
    protected function add($message, $name, $type)
30
    {
31
        return $this->set($name, [Arg::MESSAGE => $message, Arg::TYPE => $type]);
32
    }
33
34
    /**
35
     * @param string|array $message
36
     * @param string $name
37
     * @return array
38
     */
39
    function danger($message, $name = Arg::INDEX)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
40
    {
41
        return $this->add($message, $name, Arg::DANGER);
42
    }
43
44
    /**
45
     * @param string|array $message
46
     * @param string $name
47
     * @return array
48
     */
49
    function info($message, $name = Arg::INDEX)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51
        return $this->add($message, $name, Arg::INFO);
52
    }
53
54
    /**
55
     * @param string $name
56
     * @return array
57
     */
58
    function message($name = Arg::INDEX)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
59
    {
60
        ($message = $this->get($name))
61
            && $this->remove($name);
62
63
        return $message;
64
    }
65
66
    /**
67
     * @param string $name
68
     * @return void
69
     */
70
    function remove($name)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
    {
72
        unset($this->config[$name], $this->new[$name]);
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    function serialize()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
79
    {
80
        return serialize($this->new);
81
    }
82
83
    /**
84
     * @param string $name
85
     * @param array $value
86
     * @return array
87
     */
88
    function set($name, $value)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
89
    {
90
        return $this->config[$name] = $this->new[$name] = $value;
91
    }
92
93
    /**
94
     * @param string|array $message
95
     * @param string $name
96
     * @return array
97
     */
98
    function success($message, $name = Arg::INDEX)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
99
    {
100
        return $this->add($message, $name, Arg::SUCCESS);
101
    }
102
103
    /**
104
     * @param string $serialized
105
     */
106
    function unserialize($serialized)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
107
    {
108
        $this->config = unserialize($serialized);
109
    }
110
111
    /**
112
     * @param string|array $message
113
     * @param string $name
114
     * @return array
115
     */
116
    function warning($message, $name = Arg::INDEX)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
117
    {
118
        return $this->add($message, $name, Arg::WARNING);
119
    }
120
121
    /**
122
     * @param string $name
123
     * @return array
124
     */
125
    function __invoke($name = Arg::INDEX)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
126
    {
127
        return $this->message($name);
128
    }
129
}
130