Comment::getNews()   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\CommentRepository;
8
use Application\Traits\HasRichTextDescription;
9
use Doctrine\ORM\Mapping as ORM;
10
11
/**
12
 * A comment.
13
 */
14
#[ORM\Entity(CommentRepository::class)]
15
class Comment extends AbstractModel
16
{
17
    use HasRichTextDescription;
18
19
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
20
    #[ORM\ManyToOne(targetEntity: Event::class, inversedBy: 'comments')]
21
    private ?Event $event = null;
22
23
    /**
24
     * Set event.
25
     */
26
    public function setEvent(?Event $event): void
27
    {
28
        if ($this->event) {
29
            $this->event->commentRemoved($this);
30
        }
31
32
        $this->event = $event;
33
34
        if ($this->event) {
35
            $this->event->commentAdded($this);
36
        }
37
    }
38
39
    /**
40
     * Get event.
41
     */
42
    public function getEvent(): ?Event
43
    {
44
        return $this->event;
45
    }
46
47
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
48
    #[ORM\ManyToOne(targetEntity: News::class, inversedBy: 'comments')]
49
    private ?News $news = null;
50
51
    /**
52
     * Set news.
53
     */
54
    public function setNews(?News $news): void
55
    {
56
        if ($this->news) {
57
            $this->news->commentRemoved($this);
58
        }
59
60
        $this->news = $news;
61
62
        if ($this->news) {
63
            $this->news->commentAdded($this);
64
        }
65
    }
66
67
    /**
68
     * Get news.
69
     */
70
    public function getNews(): ?News
71
    {
72
        return $this->news;
73
    }
74
75
    /**
76
     * Get owner name.
77
     */
78
    public function getAuthorName(): string
79
    {
80
        return _em()->getRepository(self::class)->getAclFilter()->runWithoutAcl(function () {
81
            $user = $this->getOwner();
82
83
            return $user ? $user->getName() : 'Anonyme';
84
        });
85
    }
86
}
87