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

KnCommentTal   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 93.55%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 74
ccs 29
cts 31
cp 0.9355
rs 10
c 0
b 0
f 0
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getUserAvatarPath() 0 10 2
A getId() 0 3 1
A isDeleteable() 0 3 1
A getPostId() 0 3 1
A getRpgBehavior() 0 3 1
A getDate() 0 3 1
A getDisplayUserName() 0 8 2
A getText() 0 3 1
A getUserId() 0 3 1
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