Completed
Push — master ( 9d818b...bc28b8 )
by FX
03:09
created

Project::setFromDTO()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2017 Francois-Xavier Soubirou.
4
 *
5
 * This file is part of ci-report.
6
 *
7
 * ci-report is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * ci-report is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
declare(strict_types=1);
21
22
namespace AppBundle\Entity;
23
24
use AppBundle\DTO\ProjectDTO;
25
use Datetime;
26
use Doctrine\ORM\Mapping as ORM;
27
use JMS\Serializer\Annotation as Serializer;
28
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
29
use Symfony\Component\Validator\Constraints as Assert;
30
31
/**
32
 * Project entity class.
33
 *
34
 * @category  ci-report app
35
 *
36
 * @author    Francois-Xavier Soubirou <[email protected]>
37
 * @copyright 2017 Francois-Xavier Soubirou
38
 * @license   http://www.gnu.org/licenses/   GPLv3
39
 *
40
 * @see      https://ci-report.io
41
 *
42
 * @ORM\Table(name="cir_project")
43
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ProjectRepository")
44
 * @ORM\HasLifecycleCallbacks()
45
 *
46
 * @UniqueEntity("name", groups={"input"})
47
 */
48
class Project
49
{
50
    const DEFAULT_WARNING_LIMIT = 80;
51
    const DEFAULT_SUCCESS_LIMIT = 95;
52
53
    /**
54
     * @var int
55
     *
56
     * @ORM\Column(name="id", type="integer")
57
     * @ORM\Id
58
     * @ORM\GeneratedValue(strategy="AUTO")
59
     *
60
     * @Serializer\Exclude
61
     */
62
    private $id;
63
64
    /**
65
     * Name of the project.
66
     *
67
     * @var string
68
     *
69
     * @ORM\Column(name="name", type="string", length=50, unique=true)
70
     *
71
     * @Assert\NotBlank(groups={"input"})
72
     *
73
     * @Serializer\Groups({"public", "private"})
74
     */
75
    private $name;
76
77
    /**
78
     * Unique short name of project defined on project creation.
79
     *
80
     * @var string
81
     *
82
     * @ORM\Column(name="refid", type="string", length=50, unique=true)
83
     *
84
     * @Serializer\Groups({"public", "private"})
85
     */
86
    private $refid;
87
88
    /**
89
     * @var string
90
     *
91
     * @ORM\Column(name="token", type="string", length=50)
92
     *
93
     * @Serializer\Exclude
94
     */
95
    private $token;
96
97
    /**
98
     * Tests warning limit.
99
     *
100
     * @var int
101
     *
102
     * @ORM\Column(name="warning", type="smallint")
103
     *
104
     * @Assert\NotBlank(groups={"input"})
105
     * @Assert\Range(min=0, max=100, groups={"input"})
106
     *
107
     * @Serializer\Groups({"public", "private"})
108
     */
109
    private $warning;
110
111
    /**
112
     * Tests success limit.
113
     *
114
     * @var int
115
     *
116
     * @ORM\Column(name="success", type="smallint")
117
     *
118
     * @Assert\NotBlank(groups={"input"})
119
     * @Assert\Range(min=0, max=100, groups={"input"})
120
     *
121
     * @Serializer\Groups({"public", "private"})
122
     */
123
    private $success;
124
125
    /**
126
     * Email.
127
     *
128
     * @var string
129
     *
130
     * @ORM\Column(name="email", type="string", length=50)
131
     *
132
     * @Assert\NotBlank(groups={"input"})
133
     * @Assert\Email(strict=true, groups={"input"})
134
     *
135
     * @Serializer\Groups({"private"})
136
     */
137
    private $email;
138
139
    /**
140
     * @var DateTime
141
     *
142
     * @ORM\Column(name="created", type="datetime")
143
     *
144
     * @Serializer\Exclude
145
     */
146
    private $created;
147
148
    /**
149
     * Constructor.
150
     */
151
    public function __construct()
152
    {
153
        $this->setWarning(self::DEFAULT_WARNING_LIMIT);
154
        $this->setSuccess(self::DEFAULT_SUCCESS_LIMIT);
155
    }
156
157
    /**
158
     * Triggered on insert.
159
     *
160
     * @ORM\PrePersist
161
     */
162
    public function onPrePersist()
163
    {
164
        $this->created = new DateTime();
165
    }
166
167
    /**
168
     * Get id.
169
     *
170
     * @return int
171
     */
172
    public function getId(): int
173
    {
174
        return $this->id;
175
    }
176
177
    /**
178
     * Set name.
179
     *
180
     * @param string $name
181
     *
182
     * @return Project
183
     */
184
    public function setName(string $name): Project
185
    {
186
        $this->name = $name;
187
188
        return $this;
189
    }
190
191
    /**
192
     * Get name.
193
     *
194
     * @return string
195
     */
196
    public function getName(): string
197
    {
198
        return $this->name;
199
    }
200
201
    /**
202
     * Set refid.
203
     *
204
     * @param string $refid
205
     *
206
     * @return Project
207
     */
208
    public function setRefid(string $refid): Project
209
    {
210
        $this->refid = $refid;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Get refid.
217
     *
218
     * @return string
219
     */
220
    public function getRefid(): string
221
    {
222
        return $this->refid;
223
    }
224
225
    /**
226
     * Set token.
227
     *
228
     * @param string $token
229
     *
230
     * @return Project
231
     */
232
    public function setToken(string $token): Project
233
    {
234
        $this->token = $token;
235
236
        return $this;
237
    }
238
239
    /**
240
     * Get token.
241
     *
242
     * @return string
243
     */
244
    public function getToken(): string
245
    {
246
        return $this->token;
247
    }
248
249
    /**
250
     * Set warning limit.
251
     *
252
     * @param int $warning
253
     *
254
     * @return Project
255
     */
256
    public function setWarning(int $warning): Project
257
    {
258
        $this->warning = $warning;
259
260
        return $this;
261
    }
262
263
    /**
264
     * Get warning limit.
265
     *
266
     * @return int
267
     */
268
    public function getWarning(): int
269
    {
270
        return $this->warning;
271
    }
272
273
    /**
274
     * Set success limit.
275
     *
276
     * @param int $success
277
     *
278
     * @return Project
279
     */
280
    public function setSuccess(int $success): Project
281
    {
282
        $this->success = $success;
283
284
        return $this;
285
    }
286
287
    /**
288
     * Get success limit.
289
     *
290
     * @return int
291
     */
292
    public function getSuccess(): int
293
    {
294
        return $this->success;
295
    }
296
297
    /**
298
     * Set email.
299
     *
300
     * @param string $email
301
     *
302
     * @return Project
303
     */
304
    public function setEmail(string $email): Project
305
    {
306
        $this->email = $email;
307
308
        return $this;
309
    }
310
311
    /**
312
     * Get email.
313
     *
314
     * @return string
315
     */
316
    public function getEmail(): string
317
    {
318
        return $this->email;
319
    }
320
321
    /**
322
     * Get created date.
323
     *
324
     * @return Datetime
325
     */
326
    public function getCreated(): ?Datetime
327
    {
328
        return $this->created;
329
    }
330
331
    /**
332
     * Set from DTO object.
333
     *
334
     * @param ProjectDTO $dto DTO object
335
     *
336
     * @return Project
337
     */
338
    public function setFromDTO(ProjectDTO $dto): Project
339
    {
340
        $this->setName($dto->getName())
341
            ->setEmail($dto->getEmail())
342
            ->setWarning($dto->getWarning())
343
            ->setSuccess($dto->getSuccess());
344
345
        return $this;
346
    }
347
}
348