1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib\Message; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Stu\Lib\Information\InformationInterface; |
9
|
|
|
use Stu\Lib\Information\InformationWrapper; |
10
|
|
|
use Stu\Module\PlayerSetting\Lib\UserConstants; |
|
|
|
|
11
|
|
|
|
12
|
|
|
final class MessageCollection implements MessageCollectionInterface |
13
|
|
|
{ |
14
|
|
|
/** @var MessageInterface[] */ |
15
|
|
|
private array $messages = []; |
16
|
|
|
|
17
|
13 |
|
public function __construct(private MessageFactoryInterface $messageFactory) {} |
18
|
|
|
|
19
|
10 |
|
#[Override] |
20
|
|
|
public function add(MessageInterface $msg): void |
21
|
|
|
{ |
22
|
10 |
|
$this->messages[] = $msg; |
23
|
|
|
} |
24
|
|
|
|
25
|
4 |
|
#[Override] |
26
|
|
|
public function addMessageBy(string|array $text, ?int $recipient = null): MessageInterface |
27
|
|
|
{ |
28
|
4 |
|
$message = $this->messageFactory->createMessage( |
29
|
4 |
|
UserConstants::USER_NOONE, |
30
|
4 |
|
$recipient, |
31
|
4 |
|
is_array($text) ? $text : [$text] |
|
|
|
|
32
|
4 |
|
); |
33
|
|
|
|
34
|
4 |
|
$this->add($message); |
35
|
|
|
|
36
|
4 |
|
return $message; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
#[Override] |
40
|
|
|
public function addInformation(?string $information): InformationInterface |
41
|
|
|
{ |
42
|
|
|
if ($information !== null) { |
43
|
|
|
$this->addMessageBy($information); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
#[Override] |
50
|
|
|
public function addInformationf(string $information, ...$args): InformationInterface |
51
|
|
|
{ |
52
|
|
|
$this->addMessageBy(vsprintf($information, $args)); |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
8 |
|
#[Override] |
58
|
|
|
public function getRecipientIds(): array |
59
|
|
|
{ |
60
|
8 |
|
$recipientIds = []; |
61
|
|
|
|
62
|
8 |
|
foreach ($this->messages as $message) { |
63
|
6 |
|
if ($message->isEmpty()) { |
64
|
4 |
|
continue; |
65
|
|
|
} |
66
|
|
|
|
67
|
6 |
|
$recipientId = $message->getRecipientId(); |
68
|
|
|
|
69
|
6 |
|
if ($recipientId === null || $recipientId === UserConstants::USER_NOONE) { |
70
|
6 |
|
continue; |
71
|
|
|
} |
72
|
|
|
|
73
|
6 |
|
if (!in_array($recipientId, $recipientIds)) { |
74
|
6 |
|
$recipientIds[] = $recipientId; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
8 |
|
return $recipientIds; |
79
|
|
|
} |
80
|
|
|
|
81
|
12 |
|
#[Override] |
82
|
|
|
public function getInformationDump(?int $userId = null): InformationWrapper |
83
|
|
|
{ |
84
|
12 |
|
$result = new InformationWrapper(); |
85
|
|
|
|
86
|
12 |
|
foreach ($this->messages as $message) { |
87
|
9 |
|
if ($message->isEmpty()) { |
88
|
5 |
|
continue; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if ( |
92
|
8 |
|
$userId === null |
93
|
6 |
|
|| $message->getSenderId() === $userId |
94
|
5 |
|
|| $message->getRecipientId() === null |
95
|
8 |
|
|| $message->getRecipientId() === $userId |
96
|
|
|
) { |
97
|
8 |
|
$result->addInformationArray($message->getMessage()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
12 |
|
return $result; |
102
|
|
|
} |
103
|
|
|
|
104
|
2 |
|
#[Override] |
105
|
|
|
public function isEmpty(): bool |
106
|
|
|
{ |
107
|
2 |
|
return $this->getInformationDump()->isEmpty(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths