Failed Conditions
Push — master ( 0507ab...a124e1 )
by Sam
09:13
created

News::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\HasDescription;
9
use Application\Traits\HasName;
10
use Doctrine\Common\Collections\ArrayCollection;
11
use Doctrine\Common\Collections\Collection;
12
use Doctrine\ORM\Mapping as ORM;
13
14
/**
15
 * A news
16
 *
17
 * @ORM\Entity(repositoryClass="Application\Repository\NewsRepository")
18
 */
19
class News extends AbstractModel
20
{
21
    private const IMAGE_PATH = 'htdocs/news/';
22
23
    use HasName;
24
    use HasDescription;
25
    use HasDate;
26
27
    /**
28
     * @var Collection
29
     * @ORM\OneToMany(targetEntity="Comment", mappedBy="news")
30
     */
31
    private $comments;
32
33 3
    public function __construct()
34
    {
35 3
        $this->comments = new ArrayCollection();
36 3
    }
37
38
    /**
39
     * Get comments sent to the news
40
     *
41
     * @return Collection
42
     */
43
    public function getComments(): Collection
44
    {
45
        return $this->comments;
46
    }
47
48
    /**
49
     * Notify the news that it has a new comment
50
     * This should only be called by Comment::setNews()
51
     *
52
     * @param Comment $comment
53
     */
54
    public function commentAdded(Comment $comment): void
55
    {
56
        $this->comments->add($comment);
57
    }
58
59
    /**
60
     * Notify the news that a comment was removed
61
     * This should only be called by Comment::setNews()
62
     *
63
     * @param Comment $comment
64
     */
65
    public function commentRemoved(Comment $comment): void
66
    {
67
        $this->comments->removeElement($comment);
68
    }
69
}
70