Passed
Push — dev ( 59981f...f2247e )
by Janko
47:08
created

TrojanHorseNotifier   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 31
ccs 0
cts 18
cp 0
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A informUsersAboutTrojanHorse() 0 24 3
A __construct() 0 3 1
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Battle\AlertDetection;
4
5
use Doctrine\Common\Collections\Collection;
6
use RuntimeException;
7
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
8
use Stu\Module\PlayerSetting\Lib\UserEnum;
9
use Stu\Orm\Entity\ShipInterface;
10
11
class TrojanHorseNotifier implements TrojanHorseNotifierInterface
12
{
13
    public function __construct(
14
        private PrivateMessageSenderInterface $privateMessageSender
15
    ) {
16
    }
17
18
    public function informUsersAboutTrojanHorse(
19
        ShipInterface $incomingShip,
20
        ?ShipInterface $tractoringShip,
21
        Collection $users
22
    ): void {
23
24
        if ($tractoringShip === null) {
25
            throw new RuntimeException('this should not happen');
26
        }
27
28
        $txt = sprintf(
29
            _('Die %s von Spieler %s ist in Sektor %s eingeflogen und hat dabei die %s von Spieler %s gezogen'),
30
            $tractoringShip->getName(),
31
            $tractoringShip->getUser()->getName(),
32
            $tractoringShip->getSectorString(),
33
            $incomingShip->getName(),
34
            $incomingShip->getUser()->getName()
35
        );
36
37
        foreach ($users as $user) {
38
            $this->privateMessageSender->send(
39
                UserEnum::USER_NOONE,
40
                $user->getId(),
41
                $txt
42
            );
43
        }
44
    }
45
}
46