Failed Conditions
Push — master ( 1176d7...a379d1 )
by Adrien
16:06
created

News::getComments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasDate;
8
use Application\Traits\HasRichTextDescription;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
use Ecodev\Felix\Model\Traits\HasName;
13
14
/**
15
 * A news.
16
 *
17
 * @ORM\Entity(repositoryClass="Application\Repository\NewsRepository")
18
 */
19
class News extends AbstractModel
20
{
21
    use HasDate;
22
    use HasName;
23
    use HasRichTextDescription;
24
25
    /**
26
     * @ORM\Column(type="boolean", options={"default" = 0})
27
     */
28
    private bool $isActive = false;
29
30
    /**
31
     * @ORM\Column(type="text", length=65535, options={"default" = ""})
32
     */
33
    private string $content = '';
34
35
    /**
36
     * @var Collection<Comment>
37
     * @ORM\OneToMany(targetEntity="Comment", mappedBy="news")
38
     */
39
    private Collection $comments;
40
41 3
    public function __construct()
42
    {
43 3
        $this->comments = new ArrayCollection();
44
    }
45
46
    /**
47
     * Whether this news is shown.
48
     */
49
    public function isActive(): bool
50
    {
51
        return $this->isActive;
52
    }
53
54
    /**
55
     * Whether this news is shown.
56
     */
57
    public function setIsActive(bool $isActive): void
58
    {
59
        $this->isActive = $isActive;
60
    }
61
62
    /**
63
     * Get comments sent to the news.
64
     */
65
    public function getComments(): Collection
66
    {
67
        return $this->comments;
68
    }
69
70
    /**
71
     * Notify the news that it has a new comment
72
     * This should only be called by Comment::setNews().
73
     */
74
    public function commentAdded(Comment $comment): void
75
    {
76
        $this->comments->add($comment);
77
    }
78
79
    /**
80
     * Notify the news that a comment was removed
81
     * This should only be called by Comment::setNews().
82
     */
83
    public function commentRemoved(Comment $comment): void
84
    {
85
        $this->comments->removeElement($comment);
86
    }
87
88
    public function getContent(): string
89
    {
90
        return $this->content;
91
    }
92
93
    public function setContent(string $content): void
94
    {
95
        $this->content = $content;
96
    }
97
}
98