Passed
Pull Request — master (#1821)
by Nico
52:02 queued 25:23
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 Stu\Module\Message\Lib\PrivateMessageSenderInterface;
7
use Stu\Module\PlayerSetting\Lib\UserEnum;
8
use Stu\Orm\Entity\ShipInterface;
9
10
class TrojanHorseNotifier implements TrojanHorseNotifierInterface
11
{
12
    public function __construct(
13
        private PrivateMessageSenderInterface $privateMessageSender
14
    ) {
15
    }
16
17
    public function informUsersAboutTrojanHorse(
18
        ShipInterface $incomingShip,
19
        ?ShipInterface $tractoringShip,
20
        Collection $users
21
    ): void {
22
23
        if ($tractoringShip === null) {
24
            return;
25
        }
26
27
        $txt = sprintf(
28
            _('Die %s von Spieler %s ist in Sektor %s eingeflogen und hat dabei die %s von Spieler %s gezogen'),
29
            $tractoringShip->getName(),
30
            $tractoringShip->getUser()->getName(),
31
            $tractoringShip->getSectorString(),
32
            $incomingShip->getName(),
33
            $incomingShip->getUser()->getName()
34
        );
35
36
        foreach ($users as $user) {
37
            $this->privateMessageSender->send(
38
                UserEnum::USER_NOONE,
39
                $user->getId(),
40
                $txt
41
            );
42
        }
43
    }
44
}
45