Passed
Push — master ( f50aa1...d726cb )
by Nico
57:47 queued 28:23
created

KnCommentWrapper::getUserAvatarPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 0
dl 0
loc 18
ccs 8
cts 12
cp 0.6667
crap 3.3332
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Communication\View\ShowKnComments;
6
7
use Noodlehaus\ConfigInterface;
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\Orm\Entity\KnCommentInterface;
10
use Stu\Orm\Entity\UserInterface;
11
12
final class KnCommentWrapper implements KnCommentWrapperInterface
13
{
14 11
    public function __construct(private ConfigInterface $config, private KnCommentInterface $comment, private UserInterface $currentUser)
15
    {
16 11
    }
17
18 1
    #[Override]
19
    public function getId(): int
20
    {
21 1
        return $this->comment->getId();
22
    }
23
24 1
    #[Override]
25
    public function getPostId(): int
26
    {
27 1
        return $this->comment->getPosting()->getId();
28
    }
29
30 1
    #[Override]
31
    public function getText(): string
32
    {
33 1
        return $this->comment->getText();
34
    }
35
36 1
    #[Override]
37
    public function getDate(): int
38
    {
39 1
        return $this->comment->getDate();
40
    }
41
42 1
    #[Override]
43
    public function getUserId(): int
44
    {
45 1
        return $this->comment->getUser()->getId();
46
    }
47
48 2
    #[Override]
49
    public function getDisplayUserName(): string
50
    {
51 2
        $commentUserName = $this->comment->getUserName();
52 2
        if ($commentUserName !== '') {
53 1
            return $commentUserName;
54
        }
55
56 1
        return $this->comment->getUser()->getName();
57
    }
58
59 2
    #[Override]
60
    public function getUserAvatarPath(): string
61
    {
62 2
        if ($this->comment->getUserName() !== '') {
63 1
            return '';
64
        }
65
66 1
        if ($this->comment->getUser()->getAvatar() === '') {
67
            return sprintf(
68
                'assets/rassen/%skn.png',
69
                $this->comment->getUser()->getFactionId()
70
            );
71
        } else {
72
73 1
            return sprintf(
74 1
                '/%s/%s.png',
75 1
                $this->config->get('game.user_avatar_path'),
76 1
                $this->comment->getUser()->getAvatar()
77 1
            );
78
        }
79
    }
80
81 2
    #[Override]
82
    public function isDeleteable(): bool
83
    {
84 2
        return $this->comment->getUser() === $this->currentUser;
85
    }
86
87
    #[Override]
88
    public function getUser(): UserInterface
89
    {
90
        return $this->comment->getUser();
91
    }
92
}
93