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

DistributedMessageSender   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 34
ccs 16
cts 17
cp 0.9412
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A distributeMessageCollection() 0 24 3
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