Project::getEmail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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 App\Entity;
23
24
use App\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://www.ci-report.io
41
 *
42
 * @ORM\Table(name="cir_project")
43
 * @ORM\Entity(repositoryClass="App\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
     * Default tests warning limit.
99
     *
100
     * @var int
101
     *
102
     * @ORM\Column(name="warning", type="smallint")
103
     *
104
     * @Assert\NotBlank(groups={"input"})
105
     * @Assert\Type("integer", groups={"input"})
106
     * @Assert\Range(min=0, max=100, groups={"input"})
107
     *
108
     * @Serializer\Groups({"public", "private"})
109
     */
110
    private $warning;
111
112
    /**
113
     * Default tests success limit.
114
     *
115
     * @var int
116
     *
117
     * @ORM\Column(name="success", type="smallint")
118
     *
119
     * @Assert\NotBlank(groups={"input"})
120
     * @Assert\Type("integer", groups={"input"})
121
     * @Assert\Range(min=0, max=100, groups={"input"})
122
     *
123
     * @Serializer\Groups({"public", "private"})
124
     */
125
    private $success;
126
127
    /**
128
     * Email.
129
     *
130
     * @var string
131
     *
132
     * @ORM\Column(name="email", type="string", length=50)
133
     *
134
     * @Assert\NotBlank(groups={"input"})
135
     * @Assert\Email(strict=true, groups={"input"})
136
     *
137
     * @Serializer\Groups({"private"})
138
     */
139
    private $email;
140
141
    /**
142
     * @var DateTime
143
     *
144
     * @ORM\Column(name="created", type="datetime")
145
     *
146
     * @Serializer\Exclude
147
     */
148
    private $created;
149
150
    /**
151
     * Constructor.
152
     */
153
    public function __construct()
154
    {
155
        $this->setWarning(self::DEFAULT_WARNING_LIMIT);
156
        $this->setSuccess(self::DEFAULT_SUCCESS_LIMIT);
157
    }
158
159
    /**
160
     * Triggered on insert.
161
     *
162
     * @ORM\PrePersist
163
     */
164
    public function onPrePersist()
165
    {
166
        $this->created = new DateTime();
167
    }
168
169
    /**
170
     * Get id.
171
     *
172
     * @return int
173
     */
174
    public function getId(): int
175
    {
176
        return $this->id;
177
    }
178
179
    /**
180
     * Set name.
181
     *
182
     * @param string $name
183
     *
184
     * @return Project
185
     */
186
    public function setName(string $name): self
187
    {
188
        $this->name = $name;
189
190
        return $this;
191
    }
192
193
    /**
194
     * Get name.
195
     *
196
     * @return string
197
     */
198
    public function getName(): string
199
    {
200
        return $this->name;
201
    }
202
203
    /**
204
     * Set refid.
205
     *
206
     * @param string $refid
207
     *
208
     * @return Project
209
     */
210
    public function setRefid(string $refid): self
211
    {
212
        $this->refid = $refid;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Get refid.
219
     *
220
     * @return string
221
     */
222
    public function getRefid(): string
223
    {
224
        return $this->refid;
225
    }
226
227
    /**
228
     * Set token.
229
     *
230
     * @param string $token
231
     *
232
     * @return Project
233
     */
234
    public function setToken(string $token): self
235
    {
236
        $this->token = $token;
237
238
        return $this;
239
    }
240
241
    /**
242
     * Get token.
243
     *
244
     * @return string
245
     */
246
    public function getToken(): string
247
    {
248
        return $this->token;
249
    }
250
251
    /**
252
     * Set warning limit.
253
     *
254
     * @param int $warning
255
     *
256
     * @return Project
257
     */
258
    public function setWarning(int $warning): self
259
    {
260
        $this->warning = $warning;
261
262
        return $this;
263
    }
264
265
    /**
266
     * Get warning limit.
267
     *
268
     * @return int
269
     */
270
    public function getWarning(): int
271
    {
272
        return $this->warning;
273
    }
274
275
    /**
276
     * Set success limit.
277
     *
278
     * @param int $success
279
     *
280
     * @return Project
281
     */
282
    public function setSuccess(int $success): self
283
    {
284
        $this->success = $success;
285
286
        return $this;
287
    }
288
289
    /**
290
     * Get success limit.
291
     *
292
     * @return int
293
     */
294
    public function getSuccess(): int
295
    {
296
        return $this->success;
297
    }
298
299
    /**
300
     * Set email.
301
     *
302
     * @param string $email
303
     *
304
     * @return Project
305
     */
306
    public function setEmail(string $email): self
307
    {
308
        $this->email = $email;
309
310
        return $this;
311
    }
312
313
    /**
314
     * Get email.
315
     *
316
     * @return string
317
     */
318
    public function getEmail(): string
319
    {
320
        return $this->email;
321
    }
322
323
    /**
324
     * Get created date.
325
     *
326
     * @return DateTime
327
     */
328
    public function getCreated(): ?DateTime
329
    {
330
        return $this->created;
331
    }
332
333
    /**
334
     * Set from DTO object.
335
     *
336
     * @param ProjectDTO $dto DTO object
337
     *
338
     * @return Project
339
     */
340
    public function setFromDTO(ProjectDTO $dto): self
341
    {
342
        $this->setName($dto->getName())
343
            ->setEmail($dto->getEmail())
344
            ->setWarning($dto->getWarning())
345
            ->setSuccess($dto->getSuccess());
346
347
        return $this;
348
    }
349
}
350