Failed Conditions
Pull Request — master (#142)
by Zac
07:57
created

Test::getLastResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Overwatch\TestBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * Test
9
 *
10
 * @ORM\Table(
11
 *   name="Test",
12
 *   uniqueConstraints={
13
 *     @ORM\UniqueConstraint(name="unique_actual_expection", columns={"actual", "expectation"})
14
 *   }
15
 * )
16
 * @ORM\Entity(repositoryClass="Overwatch\TestBundle\Entity\TestRepository")
17
 * @ORM\HasLifecycleCallbacks
18
 */
19
class Test implements \JsonSerializable
20
{
21
    /**
22
     * @var integer
23
     *
24
     * @ORM\Column(name="id", type="integer")
25
     * @ORM\Id
26
     * @ORM\GeneratedValue(strategy="AUTO")
27
     */
28
    private $id;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(name="name", type="string", length=50, unique=true)
34
     */
35
    private $name;
36
37
    /**
38
     * @var string
39
     *
40
     * @ORM\Column(name="actual", type="string", length=100)
41
     */
42
    private $actual;
43
44
    /**
45
     * @var string
46
     *
47
     * @ORM\Column(name="expectation", type="string", length=50)
48
     */
49
    private $expectation;
50
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(name="expected", type="string", length=100, nullable=true)
55
     */
56
    private $expected;
57
    
58
    /**
59
     * @ORM\OneToMany(targetEntity="Overwatch\ResultBundle\Entity\TestResult", mappedBy="test")
60
     */
61
    private $results;
62
    
63
    /**
64
     * @ORM\OneToOne(targetEntity="Overwatch\ResultBundle\Entity\TestResult")
65
     * @ORM\JoinColumn(name="lastResult_id", referencedColumnName="id", onDelete="SET NULL")
66
     */
67
    private $lastResult;
68
    
69
    /**
70
     * @ORM\ManyToOne(targetEntity="TestGroup", inversedBy="tests")
71
     */
72
    private $group;
73
74
    /**
75
     * @var \DateTime
76
     *
77
     * @ORM\Column(name="created_at", type="datetime")
78
     */
79
    private $createdAt;
80
81
    /**
82
     * @var \DateTime
83
     *
84
     * @ORM\Column(name="updated_at", type="datetime")
85
     */
86 150
    private $updatedAt;
87
    
88 150
89 150
    /**
90
     * Constructor
91
     */
92
    public function __construct()
93
    {
94
        $this->results = new \Doctrine\Common\Collections\ArrayCollection();
95
    }
96 4
    
97
    /**
98 4
     * To String
99
     * 
100
     * @return string
101
     */
102
    public function __toString()
103
    {
104 10
        return $this->getName();
105
    }
106
    
107 10
    /**
108 10
     * Serialise object to JSON
109 10
     */
110 10
    public function jsonSerialize()
111 10
    {
112 10
        return [
113 10
            'id'          => $this->getId(),
114 10
            'name'        => $this->getName(),
115 10
            'actual'      => $this->getActual(),
116
            'expectation' => $this->getExpectation(),
117
            'expected'    => $this->getExpected(),
118
            'result'      => $this->getLastResult(),
119
            'createdAt'   => $this->getCreatedAt()->getTimestamp(),
120
            'updatedAt'   => $this->getUpdatedAt()->getTimestamp()
121
        ];
122
    }
123 21
    
124
    /**
125 21
     * Get id
126
     *
127
     * @return integer 
128
     */
129
    public function getId()
130
    {
131
        return $this->id;
132
    }
133
134 139
    /**
135
     * Set name
136 139
     *
137
     * @param string $name
138 139
     * @return Test
139
     */
140
    public function setName($name)
141
    {
142
        $this->name = $name;
143
144
        return $this;
145
    }
146 130
147
    /**
148 130
     * Get name
149
     *
150
     * @return string 
151
     */
152
    public function getName()
153
    {
154
        return $this->name;
155
    }
156
157 137
    /**
158
     * Set actual
159 137
     *
160
     * @param string $actual
161 137
     * @return Test
162
     */
163
    public function setActual($actual)
164
    {
165
        $this->actual = $actual;
166
167
        return $this;
168
    }
169 28
170
    /**
171 28
     * Get actual
172
     *
173
     * @return string 
174
     */
175
    public function getActual()
176
    {
177
        return $this->actual;
178
    }
179
180 137
    /**
181
     * Set expectation
182 137
     *
183
     * @param string $expectation
184 137
     * @return Test
185
     */
186
    public function setExpectation($expectation)
187
    {
188
        $this->expectation = $expectation;
189
190
        return $this;
191
    }
192 28
193
    /**
194 28
     * Get expectation
195
     *
196
     * @return string 
197
     */
198
    public function getExpectation()
199
    {
200
        return $this->expectation;
201
    }
202
203 3
    /**
204
     * Set expected
205 3
     *
206
     * @param string $expected
207 3
     * @return Test
208
     */
209
    public function setExpected($expected)
210
    {
211
        $this->expected = $expected;
212
213
        return $this;
214
    }
215 26
216
    /**
217 26
     * Get expected
218
     *
219
     * @return string 
220
     */
221
    public function getExpected()
222
    {
223
        return $this->expected;
224
    }
225
226 131
    /**
227
     * Set createdAt
228 131
     *
229 131
     * @ORM\PrePersist
230 131
     * @return Test
231
     */
232 131
    public function setCreatedAt()
233
    {
234
        if ($this->createdAt === null) {
235
            $this->createdAt = new \DateTime;
236
        }
237
        
238
        return $this;
239
    }
240 11
241
    /**
242 11
     * Get createdAt
243
     *
244
     * @return \DateTime 
245
     */
246
    public function getCreatedAt()
247
    {
248
        return $this->createdAt;
249
    }
250
251
    /**
252 131
     * Set updatedAt
253
     *
254 131
     * @ORM\PrePersist
255
     * @ORM\PreUpdate
256 131
     * @return Test
257
     */
258
    public function setUpdatedAt()
259
    {
260
        $this->updatedAt = new \DateTime;
261
262
        return $this;
263
    }
264 10
265
    /**
266 10
     * Get updatedAt
267
     *
268
     * @return \DateTime 
269
     */
270
    public function getUpdatedAt()
271
    {
272
        return $this->updatedAt;
273
    }
274
275 129
    /**
276
     * Set group
277 129
     *
278
     * @param \Overwatch\TestBundle\Entity\TestGroup $group
279 129
     * @return Test
280
     */
281
    public function setGroup(\Overwatch\TestBundle\Entity\TestGroup $group = null)
282
    {
283
        $this->group = $group;
284
285
        return $this;
286
    }
287 129
288
    /**
289 129
     * Get group
290
     *
291
     * @return \Overwatch\TestBundle\Entity\TestGroup 
292
     */
293
    public function getGroup()
294
    {
295
        return $this->group;
296
    }
297
298 1
    /**
299
     * Add results
300 1
     *
301
     * @param \Overwatch\ResultBundle\Entity\TestResult $result
302 1
     * @return Test
303
     */
304
    public function addResult(\Overwatch\ResultBundle\Entity\TestResult $result)
305
    {
306
        $this->results[] = $result;
307
308
        return $this;
309
    }
310
311
    /**
312
     * Remove results
313
     *
314
     * @param \Overwatch\ResultBundle\Entity\TestResult $result
315
     */
316
    public function removeResult(\Overwatch\ResultBundle\Entity\TestResult $result)
317
    {
318
        $this->results->removeElement($result);
319
    }
320 13
321
    /**
322 13
     * Get results
323
     *
324
     * @return \Doctrine\Common\Collections\Collection 
325
     */
326
    public function getResults()
327
    {
328
        return $this->results;
329
    }
330
    
331
    /**
332
     * Set last result
333
     * 
334
     * @param \Overwatch\ResultBundle\Entity\TestResult $result
335
     * @return \Overwatch\TestBundle\Entity\Test
336
     */
337
    public function setLastResult(\Overwatch\ResultBundle\Entity\TestResult $result)
338
    {
339
        $this->lastResult = $result;
340
        
341
        return $this;
342
    }
343
    
344
    /**
345
     * Get last result
346
     * 
347
     * @return \Overwatch\ResultBundle\Entity\TestResult
348
     */
349
    public function getLastResult()
350
    {
351
        return $this->lastResult;
352
    }
353
}
354