Passed
Push — master ( 0a21cd...0ad97c )
by Janko
05:01
created

distributeMessageCollection()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 3
nop 5
dl 0
loc 26
ccs 15
cts 15
cp 1
crap 4
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Message\Lib;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Stu\Module\PlayerSetting\Lib\UserConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserConstants was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface;
10
11
final class DistributedMessageSender implements DistributedMessageSenderInterface
12
{
13 2
    public function __construct(private PrivateMessageSenderInterface $privateMessageSender) {}
14
15 8
    #[Override]
16
    public function distributeMessageCollection(
17
        MessageCollectionInterface $messageCollection,
18
        int $senderId = UserConstants::USER_NOONE,
19
        PrivateMessageFolderTypeEnum $folderType = PrivateMessageFolderTypeEnum::SPECIAL_SYSTEM,
20
        ?string $header = null,
21
        bool $sendDumpToEveryone = false
22
    ): void {
23 8
        foreach ($messageCollection->getRecipientIds() as $recipientId) {
24 6
            $informations = $messageCollection->getInformationDump($sendDumpToEveryone ? null : $recipientId);
25
26 6
            if ($header !== null) {
27 2
                $pm = sprintf(
28 2
                    "%s\n\n%s",
29 2
                    $header,
30 2
                    $informations->getInformationsAsString()
31 2
                );
32
            } else {
33 4
                $pm =  $informations->getInformationsAsString();
34
            }
35
36 6
            $this->privateMessageSender->send(
37 6
                $senderId,
38 6
                $recipientId,
39 6
                $pm,
40 6
                $folderType
41 6
            );
42
        }
43
    }
44
}
45