Passed
Push — master ( 288b46...98b0e3 )
by Nico
31:30 queued 08:00
created

Message   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 62
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecipientId() 0 3 1
A getMessage() 0 3 1
A __construct() 0 9 2
A addMessageMerge() 0 7 2
A getSenderId() 0 3 1
A add() 0 7 2
A isEmpty() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Message;
6
7
use Stu\Module\PlayerSetting\Lib\UserEnum;
8
9
final class Message implements MessageInterface
10
{
11
    /**
12
     * @var array<string>
13
     */
14
    private array $msg = [];
15
16
    private int $senderId;
17
18
    private ?int $recipientId;
19
20
    /**
21
     * @param array<string>|null $msg
22
     */
23 36
    public function __construct(
24
        ?int $senderId = null,
25
        ?int $recipientId = null,
26
        ?array $msg = null
27
    ) {
28 36
        $this->senderId = $senderId ?? UserEnum::USER_NOONE;
29 36
        $this->recipientId = $recipientId;
30 36
        if ($msg !== null) {
31 6
            $this->msg = $msg;
32
        }
33
    }
34
35 1
    public function getSenderId(): int
36
    {
37 1
        return $this->senderId;
38
    }
39
40 12
    public function getRecipientId(): ?int
41
    {
42 12
        return $this->recipientId;
43
    }
44
45 29
    public function getMessage(): array
46
    {
47 29
        return $this->msg;
48
    }
49
50 20
    public function add(?string $msg): void
51
    {
52 20
        if ($msg === null) {
53 2
            return;
54
        }
55
56 18
        $this->msg[] = $msg;
57
    }
58
59 6
    public function addMessageMerge(array $msg): void
60
    {
61 6
        if ($msg === []) {
62 2
            return;
63
        }
64
65 4
        $this->msg = array_merge($this->msg, $msg);
66
    }
67
68 3
    public function isEmpty(): bool
69
    {
70 3
        return empty($this->getMessage());
71
    }
72
}
73