Passed
Push — master ( bf860f...1dd8f7 )
by Nico
57:55 queued 29:36
created

Message::addInformationf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
ccs 0
cts 6
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\Ship\Lib\Message;
6
7
use Stu\Lib\Information\InformationInterface;
8
use Stu\Module\PlayerSetting\Lib\UserEnum;
9
10
final class Message implements MessageInterface
11
{
12
    /**
13
     * @var array<string>
14
     */
15
    private array $msg = [];
16
17
    private int $senderId;
18
19
    private ?int $recipientId;
20
21
    /**
22
     * @param array<string>|null $msg
23
     */
24 40
    public function __construct(
25
        ?int $senderId = null,
26
        ?int $recipientId = null,
27
        ?array $msg = null
28
    ) {
29 40
        $this->senderId = $senderId ?? UserEnum::USER_NOONE;
30 40
        $this->recipientId = $recipientId;
31 40
        if ($msg !== null) {
32 8
            $this->msg = $msg;
33
        }
34
    }
35
36 1
    public function getSenderId(): int
37
    {
38 1
        return $this->senderId;
39
    }
40
41 12
    public function getRecipientId(): ?int
42
    {
43 12
        return $this->recipientId;
44
    }
45
46 31
    public function getMessage(): array
47
    {
48 31
        return $this->msg;
49
    }
50
51 21
    public function add(?string $msg): void
52
    {
53 21
        if ($msg === null) {
54 2
            return;
55
        }
56
57 19
        $this->msg[] = $msg;
58
    }
59
60
    public function addInformation(?string $information): InformationInterface
61
    {
62
        $this->add($information);
63
64
        return $this;
65
    }
66
67
    public function addInformationf(string $information, ...$args): InformationInterface
68
    {
69
        $this->add(vsprintf(
70
            $information,
71
            $args
72
        ));
73
74
        return $this;
75
    }
76
77 7
    public function addMessageMerge(array $msg): void
78
    {
79 7
        if ($msg === []) {
80 3
            return;
81
        }
82
83 4
        $this->msg = array_merge($this->msg, $msg);
84
    }
85
86 5
    public function isEmpty(): bool
87
    {
88 5
        return empty($this->getMessage());
89
    }
90
}
91