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

DistributedMessageSender::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Message\Lib;
6
7
use Stu\Module\PlayerSetting\Lib\UserEnum;
8
use Stu\Module\Ship\Lib\Message\MessageCollectionInterface;
9
10
final class DistributedMessageSender implements DistributedMessageSenderInterface
11
{
12
    private PrivateMessageSenderInterface $privateMessageSender;
13
14 1
    public function __construct(
15
        PrivateMessageSenderInterface $privateMessageSender
16
    ) {
17 1
        $this->privateMessageSender = $privateMessageSender;
18
    }
19
20 1
    public function distributeMessageCollection(
21
        MessageCollectionInterface $messageCollection,
22
        int $senderId = UserEnum::USER_NOONE,
23
        int $category = PrivateMessageFolderSpecialEnum::PM_SPECIAL_SYSTEM,
24
        string $header = null
25
    ): void {
26 1
        foreach ($messageCollection->getRecipientIds() as $recipientId) {
27 1
            $informations = $messageCollection->getInformationDump($recipientId);
28
29 1
            if ($header !== null) {
30 1
                $pm = sprintf(
31 1
                    "%s\n\n%s",
32 1
                    $header,
33 1
                    $informations->getInformationsAsString()
34 1
                );
35
            } else {
36
                $pm =  $informations->getInformationsAsString();
37
            }
38
39 1
            $this->privateMessageSender->send(
40 1
                $senderId,
41 1
                $recipientId,
42 1
                $pm,
43 1
                $category
44 1
            );
45
        }
46
    }
47
}
48