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