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

Message::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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