Incident::setIdent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace IncidentBundle\Entity;
4
5
use Doctrine\ORM\Mapping\Column;
6
use Doctrine\ORM\Mapping\Entity;
7
use Doctrine\ORM\Mapping\GeneratedValue;
8
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
9
use Doctrine\ORM\Mapping\Id;
10
use Doctrine\ORM\Mapping\Table;
11
use JMS\Serializer\Annotation\Exclude;
12
use JMS\Serializer\Annotation\ExclusionPolicy;
13
use JMS\Serializer\Annotation\Expose;
14
use JMS\Serializer\Annotation\Type;
15
use SplObserver;
16
use TonicHealthCheck\Incident\IncidentInterface;
17
18
/**
19
 * TonicHealthCheck\Entity\Incident;
20
 *
21
 * @ExclusionPolicy("none")
22
 * @HasLifecycleCallbacks
23
 * @Entity(repositoryClass="IncidentBundle\Repository\IncidentRepository")
24
 * @Table(name="incident")
25
 */
26
class Incident implements IncidentInterface
27
{
28
    /**
29
     * @var array
30
     * @Exclude
31
     */
32
    private $observers = array();
33
34
    /**
35
     * @Id
36
     * @Exclude
37
     * @Column(type="integer")
38
     * @GeneratedValue(strategy="IDENTITY")
39
     */
40
    private $id = null;
41
42
    /**
43
     * @Column(type="integer", nullable=true)
44
     */
45
    private $external_id = null;
46
47
    /**
48
     * @Column(type="string", length=128, unique=true)
49
     * @Expose
50
     */
51
    private $ident;
52
53
    /**
54
     * Type of the problems (urgent, warning, minor)
55
     *
56
     * @Column(type="string", length=32, name="`type`", nullable=true)
57
     * @Expose
58
     * @Type("string")
59
     */
60
    private $type = self::TYPE_URGENT;
61
62
    /**
63
     * @Column(type="string", length=128)
64
     * @Expose
65
     * @Type("string")
66
     */
67
    private $name;
68
69
    /**
70
     * @Column(type="text")
71
     * @Expose
72
     * @Type("string")
73
     */
74
    private $message;
75
76
    /**
77
     * @Column(type="integer", nullable=true)
78
     * @Expose
79
     * @Type("integer")
80
     */
81
    private $status = null;
82
83
    /**
84
     * Incident constructor.
85
     *
86
     * @param string $ident
87
     * @param string $name
88
     */
89 1
    public function __construct($ident, $name = '')
90
    {
91 1
        $this->setIdent($ident);
92 1
        $this->setName($name);
93 1
    }
94
95
    /**
96
     * Attach an SplObserver
97
     *
98
     * @link http://php.net/manual/en/splsubject.attach.php
99
     *
100
     * @param SplObserver $observer <p>
101
     *                              The <b>SplObserver</b> to attach.
102
     *                              </p>
103
     *
104
     * @return void
105
     *
106
     * @since 5.1.0
107
     */
108 4
    public function attach(SplObserver $observer)
109
    {
110 4
        $this->observers[spl_object_hash($observer)] = $observer;
111 4
    }
112
113
    /**
114
     * Detach an observer
115
     *
116
     * @link http://php.net/manual/en/splsubject.detach.php
117
     *
118
     * @param SplObserver $observer <p>
119
     *                              The <b>SplObserver</b> to detach.
120
     *                              </p>
121
     *
122
     * @return void
123
     *
124
     * @since 5.1.0
125
     */
126
    public function detach(SplObserver $observer)
127
    {
128
        $key = spl_object_hash($observer);
129
130
        if (isset($this->observers[$key])) {
131
            unset($this->observers[$key]);
132
        }
133
    }
134
135
    /**
136
     * Notify an observer
137
     *
138
     * @link http://php.net/manual/en/splsubject.notify.php
139
     *
140
     * @return void
141
     *
142
     * @since 5.1.0
143
     */
144 4
    public function notify()
145
    {
146
        /** @var \SplObserver $value */
147 4
        foreach ($this->observers as $value) {
148 4
            $value->update($this);
149
        }
150 4
    }
151
152
    /**
153
     * Set id
154
     *
155
     * @param int $id
156
     *
157
     * @return Incident
158
     */
159 1
    public function setId($id)
160
    {
161 1
        $this->id = $id;
162
163 1
        return $this;
164
    }
165
166
    /**
167
     * Get id
168
     *
169
     * @return int
170
     */
171 4
    public function getId()
172
    {
173 4
        return $this->id;
174
    }
175
176
    /**
177
     * Set ident
178
     *
179
     * @param string $ident
180
     *
181
     * @return Incident
182
     */
183 1
    public function setIdent($ident)
184
    {
185 1
        $this->ident = $ident;
186
187 1
        return $this;
188
    }
189
190
    /**
191
     * Get ident
192
     *
193
     * @return string
194
     */
195
    public function getIdent()
196
    {
197
        return $this->ident;
198
    }
199
200
    /**
201
     * Get type
202
     *
203
     * @return string
204
     */
205 4
    public function getType()
206
    {
207 4
        return $this->type;
208
    }
209
210
    /**
211
     * Set type
212
     *
213
     * @param string $type
214
     */
215
    public function setType($type)
216
    {
217
        $this->type = $type;
218
    }
219
220
    /**
221
     * Set name
222
     *
223
     * @param string $name
224
     *
225
     * @return Incident
226
     */
227 1
    public function setName($name)
228
    {
229 1
        $this->name = $name;
230
231 1
        return $this;
232
    }
233
234
    /**
235
     * Get name
236
     *
237
     * @return string
238
     */
239
    public function getName()
240
    {
241
        return $this->name;
242
    }
243
244
    /**
245
     * Set message
246
     *
247
     * @param string $message
248
     *
249
     * @return Incident
250
     */
251 1
    public function setMessage($message)
252
    {
253 1
        $this->message = $message;
254
255 1
        return $this;
256
    }
257
258
    /**
259
     * Get message
260
     *
261
     * @return string
262
     */
263
    public function getMessage()
264
    {
265
        return $this->message;
266
    }
267
268
    /**
269
     * Set status
270
     *
271
     * @param int $status
272
     *
273
     * @return Incident
274
     */
275 1
    public function setStatus($status)
276
    {
277 1
        $this->status = $status;
278
279 1
        return $this;
280
    }
281
282
    /**
283
     * Get status
284
     *
285
     * @return int
286
     */
287
    public function getStatus()
288
    {
289
        return $this->status;
290
    }
291
292
    /**
293
     * Set externalId
294
     *
295
     * @param int $externalId
296
     *
297
     * @return Incident
298
     */
299
    public function setExternalId($externalId)
300
    {
301
        $this->external_id = $externalId;
302
303
        return $this;
304
    }
305
306
    /**
307
     * Get externalId
308
     *
309
     * @return int
310
     */
311
    public function getExternalId()
312
    {
313
        return $this->external_id;
314
    }
315
}
316