Completed
Branch FET-Wait-List (2b1ad0)
by
unknown
128:56 queued 117:50
created

NoticesContainer   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 233
Duplicated Lines 9.44 %

Coupling/Cohesion

Components 4
Dependencies 1

Importance

Changes 0
Metric Value
dl 22
loc 233
rs 10
c 0
b 0
f 0
wmc 16
lcom 4
cbo 1

16 Methods

Rating   Name   Duplication   Size   Complexity  
A addInformation() 0 11 1
A addAttention() 11 11 1
A addError() 0 11 1
A addSuccess() 11 11 1
A hasInformation() 0 4 1
A hasAttention() 0 4 1
A hasError() 0 4 1
A hasSuccess() 0 4 1
A countInformation() 0 4 1
A countAttention() 0 4 1
A countError() 0 4 1
A countSuccess() 0 4 1
A getInformation() 0 4 1
A getAttention() 0 4 1
A getError() 0 4 1
A getSuccess() 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 EventEspresso\core\services\notices;
4
5
use EventEspresso\core\exceptions\InvalidDataTypeException;
6
7
defined('EVENT_ESPRESSO_VERSION') || exit;
8
9
10
11
/**
12
 * Class NoticesContainer
13
 * Container for holding multiple Notice objects until they can be processed
14
 *
15
 * @package       Event Espresso
16
 * @author        Brent Christensen
17
 * @since         $VID:$
18
 */
19
class NoticesContainer implements NoticesContainerInterface
20
{
21
22
23
    /**
24
     * @var NoticeInterface[] $information
25
     */
26
    private $information = array();
27
28
29
    /**
30
     * @var NoticeInterface[] $attention
31
     */
32
    private $attention = array();
33
34
35
    /**
36
     * @var NoticeInterface[] $error
37
     */
38
    private $error = array();
39
40
41
    /**
42
     * @var NoticeInterface[] $success
43
     */
44
    private $success = array();
45
46
47
    /**
48
     * @param string $notice
49
     * @param bool   $dismissible
50
     * @param string $file
51
     * @param string $func
52
     * @param string $line
53
     * @throws InvalidDataTypeException
54
     */
55
    public function addInformation($notice, $dismissible = true, $file = '', $func = '', $line = '')
56
    {
57
        $this->information[] = new Notice(
58
            Notice::INFORMATION,
59
            $notice,
60
            $dismissible,
61
            $file,
62
            $func,
63
            $line
64
        );
65
    }
66
67
68
69
    /**
70
     * @param string $notice
71
     * @param bool   $dismissible
72
     * @param string $file
73
     * @param string $func
74
     * @param string $line
75
     * @throws InvalidDataTypeException
76
     */
77 View Code Duplication
    public function addAttention($notice, $dismissible = true, $file = '', $func = '', $line = '')
78
    {
79
        $this->attention[] = new Notice(
80
            Notice::ATTENTION,
81
            $notice,
82
            $dismissible,
83
            $file,
84
            $func,
85
            $line
86
        );
87
    }
88
89
90
91
    /**
92
     * @param string $notice
93
     * @param bool   $dismissible
94
     * @param string $file
95
     * @param string $func
96
     * @param string $line
97
     * @throws InvalidDataTypeException
98
     */
99
    public function addError($notice, $dismissible = true, $file, $func, $line)
100
    {
101
        $this->error[] = new Notice(
102
            Notice::ERROR,
103
            $notice,
104
            $dismissible,
105
            $file,
106
            $func,
107
            $line
108
        );
109
    }
110
111
112
113
    /**
114
     * @param string $notice
115
     * @param bool   $dismissible
116
     * @param string $file
117
     * @param string $func
118
     * @param string $line
119
     * @throws InvalidDataTypeException
120
     */
121 View Code Duplication
    public function addSuccess($notice, $dismissible = true, $file = '', $func = '', $line = '')
122
    {
123
        $this->success[] = new Notice(
124
            Notice::SUCCESS,
125
            $notice,
126
            $dismissible,
127
            $file,
128
            $func,
129
            $line
130
        );
131
    }
132
133
134
    /**
135
     * @return boolean
136
     */
137
    public function hasInformation()
138
    {
139
        return ! empty($this->information);
140
    }
141
142
143
144
    /**
145
     * @return boolean
146
     */
147
    public function hasAttention()
148
    {
149
        return ! empty($this->attention);
150
    }
151
152
153
154
    /**
155
     * @return boolean
156
     */
157
    public function hasError()
158
    {
159
        return ! empty($this->error);
160
    }
161
162
163
164
    /**
165
     * @return boolean
166
     */
167
    public function hasSuccess()
168
    {
169
        return ! empty($this->success);
170
    }
171
172
173
    /**
174
     * @return int
175
     */
176
    public function countInformation()
177
    {
178
        return count($this->information);
179
    }
180
181
182
183
    /**
184
     * @return int
185
     */
186
    public function countAttention()
187
    {
188
        return count($this->attention);
189
    }
190
191
192
193
    /**
194
     * @return int
195
     */
196
    public function countError()
197
    {
198
        return count($this->error);
199
    }
200
201
202
203
    /**
204
     * @return int
205
     */
206
    public function countSuccess()
207
    {
208
        return count($this->success);
209
    }
210
211
212
    /**
213
     * @return NoticeInterface[]
214
     */
215
    public function getInformation()
216
    {
217
        return $this->information;
218
    }
219
220
221
222
    /**
223
     * @return NoticeInterface[]
224
     */
225
    public function getAttention()
226
    {
227
        return $this->attention;
228
    }
229
230
231
232
    /**
233
     * @return NoticeInterface[]
234
     */
235
    public function getError()
236
    {
237
        return $this->error;
238
    }
239
240
241
242
    /**
243
     * @return NoticeInterface[]
244
     */
245
    public function getSuccess()
246
    {
247
        return $this->success;
248
    }
249
250
251
}
252