Passed
Push — master ( 69410e...6e6431 )
by Nico
42:43 queued 11:08
created

KnCommentTal::getRpgBehavior()   A

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 Stu\Module\Communication\View\ShowKnComments;
6
7
use Noodlehaus\ConfigInterface;
8
use Stu\Component\Player\UserRpgBehaviorEnum;
9
use Stu\Orm\Entity\KnCommentInterface;
10
use Stu\Orm\Entity\UserInterface;
11
12
final class KnCommentTal implements KnCommentTalInterface
13
{
14
    private KnCommentInterface $comment;
15
16
    private UserInterface $currentUser;
17
18
    private ConfigInterface $config;
19
20 11
    public function __construct(
21
        ConfigInterface $config,
22
        KnCommentInterface $comment,
23
        UserInterface $currentUser
24
    ) {
25 11
        $this->comment = $comment;
26 11
        $this->currentUser = $currentUser;
27 11
        $this->config = $config;
28
    }
29
30 1
    public function getId(): int
31
    {
32 1
        return $this->comment->getId();
33
    }
34
35 1
    public function getPostId(): int
36
    {
37 1
        return $this->comment->getPosting()->getId();
38
    }
39
40 1
    public function getText(): string
41
    {
42 1
        return $this->comment->getText();
43
    }
44
45 1
    public function getDate(): int
46
    {
47 1
        return $this->comment->getDate();
48
    }
49
50 1
    public function getUserId(): int
51
    {
52 1
        return $this->comment->getUser()->getId();
53
    }
54
55 2
    public function getDisplayUserName(): string
56
    {
57 2
        $commentUserName = $this->comment->getUserName();
58 2
        if ($commentUserName !== '') {
59 1
            return $commentUserName;
60
        }
61
62 1
        return $this->comment->getUser()->getName();
63
    }
64
65 2
    public function getUserAvatarPath(): string
66
    {
67 2
        if ($this->comment->getUserName() !== '') {
68 1
            return '';
69
        }
70
71 1
        return sprintf(
72 1
            '/%s/%s.png',
73 1
            $this->config->get('game.user_avatar_path'),
74 1
            $this->comment->getUser()->getAvatar()
75 1
        );
76
    }
77
78 2
    public function isDeleteable(): bool
79
    {
80 2
        return $this->comment->getUser() === $this->currentUser;
81
    }
82
83
    public function getRpgBehavior(): UserRpgBehaviorEnum
84
    {
85
        return $this->comment->getUser()->getRpgBehavior();
86
    }
87
}
88