Completed
Push — master ( 759a3c...0a5dc9 )
by Mohamed
04:06
created

Card::setUpdated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 9
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.6666
1
<?php
2
3
/*
4
 * This file is part of the Moo\FlashCardBundle package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Moo\FlashCardBundle\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Gedmo\Mapping\Annotation as Gedmo;
17
use Symfony\Component\Validator\Constraints as Assert;
18
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
19
20
/**
21
 * Card is the entity class that represents a record from the database.
22
 *
23
 * @author Mohamed Alsharaf <[email protected]>
24
 * @ORM\Table(name="card")
25
 * @ORM\Entity(repositoryClass="Moo\FlashCardBundle\Repository\Card")
26
 * @ORM\HasLifecycleCallbacks()
27
 * @UniqueEntity(
28
 *     fields={"title"},
29
 *     message="There is an existing card with the same title."
30
 * )
31
 */
32
class Card
33
{
34
    /**
35
     * @var int
36
     *
37
     * @ORM\Column(name="id", type="integer", nullable=false)
38
     * @ORM\Id
39
     * @ORM\GeneratedValue(strategy="IDENTITY")
40
     */
41
    private $id;
42
43
    /**
44
     * @var string
45
     *
46
     * @Gedmo\Slug(fields={"title"}, separator="-")
47
     * @ORM\Column(name="slug", type="string", length=100, nullable=false, unique=true)
48
     */
49
    private $slug;
50
51
    /**
52
     * @var bool
53
     *
54
     * @ORM\Column(name="active", type="boolean", nullable=false)
55
     */
56
    private $active = false;
57
58
    /**
59
     * @var string
60
     *
61
     * @ORM\Column(name="title", type="string", length=255, nullable=false, unique=true)
62
     * @Assert\NotBlank()
63
     * @Assert\Length(
64
     *      min = "5",
65
     *      max = "255",
66
     *      minMessage = "Card title must be at least {{ limit }} characters length",
67
     *      maxMessage = "Card title cannot be longer than {{ limit }} characters length"
68
     * )
69
     */
70
    private $title;
71
72
    /**
73
     * @var string
74
     *
75
     * @ORM\Column(name="content", type="text", nullable=false)
76
     * @Assert\NotBlank()
77
     */
78
    private $content;
79
80
    /**
81
     * @var \DateTime
82
     *
83
     * @ORM\Column(name="created", type="datetime", nullable=false)
84
     */
85
    private $created;
86
87
    /**
88
     * @var \DateTime
89
     *
90
     * @ORM\Column(name="updated", type="datetime", nullable=false)
91
     */
92
    private $updated;
93
94
    /**
95
     * @var string
96
     *
97
     * @ORM\Column(name="meta_keywords", type="string", length=255, nullable=true)
98
     */
99
    private $metaKeywords;
100
101
    /**
102
     * @var string
103
     *
104
     * @ORM\Column(name="meta_description", type="string", length=255, nullable=true)
105
     */
106
    private $metaDescription;
107
108
    /**
109
     * @var int
110
     *
111
     * @ORM\Column(name="views", type="integer", nullable=false)
112
     */
113
    private $views = '0';
114
115
    /**
116
     * @var Category
117
     *
118
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="cards", fetch="EAGER")
119
     * @ORM\JoinColumns({
120
     *   @ORM\JoinColumn(name="category_id", referencedColumnName="id")
121
     * })
122
     * @Assert\NotBlank()
123
     */
124
    private $category;
125
126
    /**
127
     * @ORM\OneToMany(targetEntity="CardView", mappedBy="card")
128
     */
129
    private $cardViews;
130
131 10
    public function __construct()
132
    {
133 10
        $this->cardViews = new ArrayCollection();
134 10
    }
135
136
    /**
137
     * Get id
138
     *
139
     * @return int
140
     */
141 3
    public function getId()
142
    {
143 3
        return $this->id;
144
    }
145
146
    /**
147
     * Set slug
148
     *
149
     * @param string $slug
150
     *
151
     * @return Card
152
     */
153 1
    public function setSlug($slug)
154
    {
155 1
        $this->slug = $slug;
156
157 1
        return $this;
158
    }
159
160
    /**
161
     * Get slug
162
     *
163
     * @return string
164
     */
165 4
    public function getSlug()
166
    {
167 4
        return $this->slug;
168
    }
169
170
    /**
171
     * Set isActive
172
     *
173
     * @param bool $isActive
174
     *
175
     * @return Card
176
     */
177 7
    public function setActive($isActive)
178
    {
179 7
        $this->active = $isActive;
180
181 7
        return $this;
182
    }
183
184
    /**
185
     * Get isActive
186
     *
187
     * @return bool
188
     */
189 5
    public function isActive()
190
    {
191 5
        return $this->active;
192
    }
193
194
    /**
195
     * Set title
196
     *
197
     * @param string $title
198
     *
199
     * @return Card
200
     */
201 9
    public function setTitle($title)
202
    {
203 9
        $this->title = $title;
204
205 9
        return $this;
206
    }
207
208
    /**
209
     * Get title
210
     *
211
     * @return string
212
     */
213 4
    public function getTitle()
214
    {
215 4
        return $this->title;
216
    }
217
218
    /**
219
     * Set content
220
     *
221
     * @param string $content
222
     *
223
     * @return Card
224
     */
225 8
    public function setContent($content)
226
    {
227 8
        $this->content = $content;
228
229 8
        return $this;
230
    }
231
232
    /**
233
     * Get content
234
     *
235
     * @return string
236
     */
237 4
    public function getContent()
238
    {
239 4
        return $this->content;
240
    }
241
242
    /**
243
     * Set created
244
     *
245
     * @param \DateTime $created
246
     *
247
     * @return Card
248
     */
249 5 View Code Duplication
    public function setCreated($created = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
    {
251 5
        if ($created === null) {
252 5
            $created = new \DateTime();
253 5
            $this->setUpdated($created);
254
        }
255 5
        $this->created = $created;
256
257 5
        return $this;
258
    }
259
260
    /**
261
     * Get created
262
     *
263
     * @return \DateTime
264
     */
265 1
    public function getCreated()
266
    {
267 1
        return $this->created;
268
    }
269
270
    /**
271
     * Set updated
272
     *
273
     * @param \DateTime $updated
274
     *
275
     * @return Card
276
     */
277 5 View Code Duplication
    public function setUpdated($updated = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
278
    {
279 5
        if ($updated === null) {
280
            $updated = new \DateTime();
281
        }
282 5
        $this->updated = $updated;
283
284 5
        return $this;
285
    }
286
287
    /**
288
     * Get updated
289
     *
290
     * @return \DateTime
291
     */
292 4
    public function getUpdated()
293
    {
294 4
        return $this->updated;
295
    }
296
297
    /**
298
     * Set meta keywords
299
     *
300
     * @param string $keywords
301
     *
302
     * @return Card
303
     */
304 5
    public function setMetaKeywords($keywords)
305
    {
306 5
        $this->metaKeywords = $keywords;
307
308 5
        return $this;
309
    }
310
311
    /**
312
     * Get Meta keywords
313
     *
314
     * @return string
315
     */
316 2
    public function getMetaKeywords()
317
    {
318 2
        return $this->metaKeywords;
319
    }
320
321
    /**
322
     * Set meta description
323
     *
324
     * @param string $description
325
     *
326
     * @return Card
327
     */
328 5
    public function setMetaDescription($description)
329
    {
330 5
        $this->metaDescription = $description;
331
332 5
        return $this;
333
    }
334
335
    /**
336
     * Get meta description
337
     *
338
     * @return string
339
     */
340 1
    public function getMetaDescription()
341
    {
342 1
        return $this->metaDescription;
343
    }
344
345
    /**
346
     * Set views
347
     *
348
     * @param int $views
349
     *
350
     * @return Card
351
     */
352 5
    public function setViews($views)
353
    {
354 5
        $this->views = $views;
355
356 5
        return $this;
357
    }
358
359
    /**
360
     * Get views
361
     *
362
     * @return int
363
     */
364 3
    public function getViews()
365
    {
366 3
        return $this->views;
367
    }
368
369
    /**
370
     * Set category
371
     *
372
     * @param Category $category
373
     *
374
     * @return Card
375
     */
376 5
    public function setCategory(Category $category = null)
377
    {
378 5
        $this->category = $category;
379
380 5
        return $this;
381
    }
382
383
    /**
384
     * Get category
385
     *
386
     * @return Category
387
     */
388 5
    public function getCategory()
389
    {
390 5
        return $this->category;
391
    }
392
393
    /**
394
     * @ORM\PrePersist
395
     */
396
    public function prePersist()
397
    {
398
        $this->setCreated();
399
    }
400
401
    /**
402
     * @ORM\PreUpdate
403
     */
404
    public function preUpdate()
405
    {
406
        $this->setUpdated();
407
    }
408
409
    public function __toString()
410
    {
411
        return $this->getTitle() ?: 'New Card';
412
    }
413
}
414