News::isActive()   A
last analyzed

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