Passed
Pull Request — master (#2177)
by Nico
30:59 queued 20:55
created

KnArchiveItem::getUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
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 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...
8
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...
9
use Stu\Module\Template\StatusBarFactoryInterface;
10
use Stu\Orm\Entity\KnPostArchiv;
11
use Stu\Orm\Entity\RpgPlotArchiv;
12
use Stu\Orm\Entity\User;
13
use Stu\Orm\Repository\KnCommentArchivRepositoryInterface;
14
15
final class KnArchiveItem implements KnArchiveItemInterface
16
{
17
    private ?RpgPlotArchiv $plot = null;
18
19 1
    public function __construct(
20
        private KnBbCodeParser $bbcodeParser,
21
        private StatusBarFactoryInterface $statusBarFactory,
22
        private KnPostArchiv $post,
23
        private KnCommentArchivRepositoryInterface $knCommentArchivRepository
24 1
    ) {}
25
26 1
    #[Override]
27
    public function getId(): int
28
    {
29 1
        return $this->post->getId();
30
    }
31
32 1
    #[Override]
33
    public function getFormerId(): int
34
    {
35 1
        return $this->post->getFormerId();
36
    }
37
38 1
    #[Override]
39
    public function getTitle(): ?string
40
    {
41 1
        return $this->post->getTitle();
42
    }
43
44 1
    #[Override]
45
    public function getText(): string
46
    {
47 1
        return $this->bbcodeParser->parse($this->post->getText())->getAsHTML();
48
    }
49
50 1
    #[Override]
51
    public function getUsername(): string
52
    {
53 1
        $username = $this->post->getUsername();
54 1
        $userId = $this->post->getdelUserId() ?? $this->post->getUserId();
55
56 1
        return sprintf('%s (%d)', $username, $userId);
57
    }
58
59
    #[Override]
60
    public function getUserId(): int
61
    {
62
        return $this->post->getUserId() ?? 0;
63
    }
64
65 1
    #[Override]
66
    public function getDate(): int
67
    {
68 1
        return $this->post->getDate();
69
    }
70
71 1
    #[Override]
72
    public function getEditDate(): ?int
73
    {
74 1
        return $this->post->getEditDate();
75
    }
76
77 1
    #[Override]
78
    public function getRpgPlot(): ?RpgPlotArchiv
79
    {
80 1
        return $this->plot;
81
    }
82
83
    #[Override]
84
    public function setPlot(?RpgPlotArchiv $plot): void
85
    {
86
        $this->plot = $plot;
87
    }
88
89 1
    #[Override]
90
    public function getVersion(): ?string
91
    {
92 1
        return $this->post->getVersion();
93
    }
94
95
    #[Override]
96
    public function getPost(): KnPostArchiv
97
    {
98
        return $this->post;
99
    }
100
101
    /**
102
     * @return array<mixed>
103
     */
104
    #[Override]
105
    public function getRatings(): array
106
    {
107
        return $this->post->getRatings();
108
    }
109
110 1
    #[Override]
111
    public function getRatingBar(): string
112
    {
113 1
        $ratingAmount = count($this->post->getRatings());
114
115 1
        if ($ratingAmount === 0) {
116
            return '';
117
        }
118
119 1
        return $this->statusBarFactory
120 1
            ->createStatusBar()
121 1
            ->setColor(StatusBarColorEnum::STATUSBAR_YELLOW)
122 1
            ->setLabel('Bewertung')
123 1
            ->setMaxValue($ratingAmount)
124 1
            ->setValue($this->getRating())
125 1
            ->render();
126
    }
127
128 1
    #[Override]
129
    public function getRating(): int
130
    {
131 1
        return (int) array_sum(
132 1
            array_filter(
133 1
                $this->post->getRatings(),
134 1
                static fn(int $value): bool => $value > 0
135 1
            )
136 1
        );
137
    }
138
139
    #[Override]
140
    public function userCanRate(): bool
141
    {
142
        return false;
143
    }
144
145 1
    #[Override]
146
    public function getCommentCount(): int
147
    {
148 1
        return $this->knCommentArchivRepository->getAmountByFormerId($this->post->getFormerId());
149
    }
150
151 1
    #[Override]
152
    public function getDivClass(): string
153
    {
154 1
        return 'box kn_archive_post';
155
    }
156
}
157