Passed
Push — dev ( d85471...98511f )
by Janko
18:01
created

Conversation   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 21
c 2
b 0
f 1
dl 0
loc 54
ccs 26
cts 26
cp 1
rs 10
wmc 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Game\Lib\View\Provider\Message;
6
7
use Override;
8
use Stu\Module\Message\Lib\PrivateMessageListItem;
9
use Stu\Orm\Entity\PrivateMessageInterface;
10
use Stu\Orm\Entity\UserInterface;
11
use Stu\Orm\Repository\ContactRepositoryInterface;
12
use Stu\Orm\Repository\PrivateMessageRepositoryInterface;
13
14
final class Conversation extends PrivateMessageListItem
15
{
16
    private const int MAX_PREVIEW_CHARS = 200;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 16 at column 22
Loading history...
17
18 1
    public function __construct(
19
        private PrivateMessageInterface $message,
20
        private int $unreadPmCount,
21
        private string $dateString,
22
        UserInterface $currentUser,
23
        PrivateMessageRepositoryInterface $privateMessageRepository,
24
        ContactRepositoryInterface $contactRepository
25
    ) {
26 1
        parent::__construct(
27 1
            $privateMessageRepository,
28 1
            $contactRepository,
29 1
            $message,
30 1
            $currentUser
31 1
        );
32
    }
33
34 1
    #[Override]
35
    public function isMarkableAsNew(): bool
36
    {
37 1
        return $this->message->getNew();
38
    }
39
40 1
    public function getUnreadMessageCount(): int
41
    {
42 1
        return $this->unreadPmCount;
43
    }
44
45 1
    public function getLastHeadline(): string
46
    {
47 1
        $isCutOff = strlen($this->message->getText()) > self::MAX_PREVIEW_CHARS;
48
49 1
        return sprintf(
50 1
            '%s%s%s',
51 1
            $this->message->getInboxPm() === null ? sprintf(
52 1
                '%s: ',
53 1
                $this->getOtherUser()->getName()
54 1
            ) : '',
55 1
            substr($this->message->getText(), 0, self::MAX_PREVIEW_CHARS),
56 1
            $isCutOff ? '...' : ''
57 1
        );
58
    }
59
60 1
    public function getOtherUser(): UserInterface
61
    {
62 1
        return $this->message->getSender();
63
    }
64
65 1
    public function getDateString(): string
66
    {
67 1
        return $this->dateString;
68
    }
69
}
70