Passed
Push — dev ( 2d398e...250fad )
by Janko
12:46
created

KnItem::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Communication\Kn;
6
7
use Doctrine\Common\Collections\Collection;
8
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Stu\Module\Template\StatusBarColorEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Template\StatusBarColorEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Stu\Module\Template\StatusBarFactoryInterface;
12
use Stu\Orm\Entity\KnPostInterface;
13
use Stu\Orm\Entity\RpgPlotInterface;
14
use Stu\Orm\Entity\UserInterface;
15
use Stu\Orm\Repository\KnCommentRepositoryInterface;
16
17
final class KnItem implements KnItemInterface
18
{
19
    private ?int $mark = null;
20
21
    private bool $isHighlighted = false;
22
23 28
    public function __construct(
24
        private KnBbCodeParser $bbcodeParser,
25
        private KnCommentRepositoryInterface $knCommentRepository,
26
        private StatusBarFactoryInterface $statusBarFactory,
27
        private KnPostInterface $post,
28
        private UserInterface $currentUser
29 28
    ) {}
30
31 5
    #[Override]
32
    public function getId(): int
33
    {
34 5
        return $this->post->getId();
35
    }
36
37 5
    #[Override]
38
    public function getUser(): UserInterface
39
    {
40 5
        return $this->post->getUser();
41
    }
42
43 1
    #[Override]
44
    public function getUserId(): int
45
    {
46 1
        return $this->post->getUserId();
47
    }
48
49 4
    #[Override]
50
    public function getTitle(): ?string
51
    {
52 4
        return $this->post->getTitle();
53
    }
54
55 4
    #[Override]
56
    public function getText(): string
57
    {
58 4
        return $this->bbcodeParser->parse($this->post->getText())->getAsHTML();
59
    }
60
61 7
    #[Override]
62
    public function getDate(): int
63
    {
64 7
        return $this->post->getDate();
65
    }
66
67 4
    #[Override]
68
    public function getEditDate(): int
69
    {
70 4
        return $this->post->getEditDate();
71
    }
72
73 5
    #[Override]
74
    public function isEditAble(): bool
75
    {
76 5
        return $this->getDate() > time() - 600 && $this->post->getUser() === $this->currentUser;
77
    }
78
79 5
    #[Override]
80
    public function getPlot(): ?RpgPlotInterface
81
    {
82 5
        return $this->post->getRpgPlot();
83
    }
84
85 3
    #[Override]
86
    public function getCharacters(): Collection
87
    {
88 3
        return $this->post->getKnCharacters();
89
    }
90
91 5
    #[Override]
92
    public function getCommentCount(): int
93
    {
94 5
        return $this->knCommentRepository->getAmountByPost($this->post);
95
    }
96
97 5
    #[Override]
98
    public function displayContactLinks(): bool
99
    {
100 5
        $user = $this->post->getUser();
101 5
        return $user !== $this->currentUser && $user->getId() !== UserEnum::USER_NOONE;
102
    }
103
104 4
    #[Override]
105
    public function getUserName(): string
106
    {
107 4
        return $this->post->getUsername();
108
    }
109
110 3
    #[Override]
111
    public function isUserDeleted(): bool
112
    {
113 3
        return $this->post->getUserId() !== 1;
114
    }
115
116 5
    #[Override]
117
    public function isNewerThanMark(): bool
118
    {
119 5
        return $this->post->getId() > $this->currentUser->getKnMark();
120
    }
121
122 5
    #[Override]
123
    public function userCanRate(): bool
124
    {
125 5
        return !$this->userHasRated() && $this->currentUser !== $this->post->getUser() && $this->currentUser->getId() > 100;
126
    }
127
128 7
    #[Override]
129
    public function userHasRated(): bool
130
    {
131 7
        return array_key_exists($this->currentUser->getId(), $this->post->getRatings());
132
    }
133
134 1
    #[Override]
135
    public function getMark(): ?int
136
    {
137 1
        return $this->mark;
138
    }
139
140 1
    #[Override]
141
    public function setMark(int $mark): void
142
    {
143 1
        $this->mark = $mark;
144
    }
145
146 3
    #[Override]
147
    public function getDivClass(): string
148
    {
149 3
        return $this->isHighlighted ? 'red_box' : 'box';
150
    }
151
152 1
    #[Override]
153
    public function setIsHighlighted(bool $isHighlighted): void
154
    {
155 1
        $this->isHighlighted = $isHighlighted;
156
    }
157
158 5
    #[Override]
159
    public function getRating(): int
160
    {
161 5
        return (int) array_sum(
162 5
            array_filter(
163 5
                $this->post->getRatings(),
164 5
                static fn(int $value): bool => $value > 0
165 5
            )
166 5
        );
167
    }
168
169 5
    #[Override]
170
    public function getRatingBar(): string
171
    {
172 5
        $ratingAmount = count($this->post->getRatings());
173
174 5
        if ($ratingAmount === 0) {
175 1
            return '';
176
        }
177
178 4
        return $this->statusBarFactory
179 4
            ->createStatusBar()
180 4
            ->setColor(StatusBarColorEnum::STATUSBAR_YELLOW)
181 4
            ->setLabel('Bewertung')
182 4
            ->setMaxValue($ratingAmount)
183 4
            ->setValue($this->getRating())
184 4
            ->render();
185
    }
186 3
    #[Override]
187
    public function hasTranslation(): bool
188
    {
189 3
        $text = $this->getText();
190 3
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
191
    }
192
}
193