Passed
Pull Request — master (#1821)
by Nico
52:02 queued 25:23
created

AlertDetection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 5
dl 0
loc 7
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Battle\AlertDetection;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Stu\Lib\Information\InformationInterface;
7
use Stu\Module\Ship\Lib\Battle\Party\AlertStateBattleParty;
8
use Stu\Module\Ship\Lib\Battle\Party\BattlePartyFactoryInterface;
9
use Stu\Orm\Entity\ShipInterface;
10
11
class AlertDetection implements AlertDetectionInterface
12
{
13 2
    public function __construct(
14
        private AlertedShipsDetectionInterface $alertedShipsDetection,
15
        private SkipDetectionInterface $skipDetection,
16
        private BattlePartyFactoryInterface $battlePartyFactory,
17
        private TrojanHorseNotifierInterface $trojanHorseNotifier,
18
        private AlertedShipInformationInterface $alertedShipInformation
19
    ) {
20 2
    }
21
22 2
    public function detectAlertedBattleParties(
23
        ShipInterface $incomingShip,
24
        InformationInterface $informations,
25
        ?ShipInterface $tractoringShip = null
26
    ): array {
27
28 2
        $alertedWrappers = $this->alertedShipsDetection->getAlertedShipsOnLocation($incomingShip);
29 2
        if ($alertedWrappers->isEmpty()) {
30 1
            return [];
31
        }
32
33
        /** @var array<int, AlertStateBattleParty> */
34 1
        $battleParties = [];
35 1
        $usersToInformAboutTrojanHorse = new ArrayCollection();
36
37 1
        foreach ($alertedWrappers as $alertedWrapper) {
38
39 1
            $alertedShip = $alertedWrapper->get();
40
41 1
            if ($this->skipDetection->isSkipped($incomingShip, $alertedShip, $tractoringShip, $usersToInformAboutTrojanHorse)) {
42 1
                continue;
43
            }
44
45 1
            $battleParties[$alertedShip->getId()] = $this->battlePartyFactory->createAlertStateBattleParty($alertedWrapper);
46
        }
47
48 1
        $this->trojanHorseNotifier->informUsersAboutTrojanHorse(
49 1
            $incomingShip,
50 1
            $tractoringShip,
51 1
            $usersToInformAboutTrojanHorse
52 1
        );
53
54 1
        $this->alertedShipInformation->addAlertedShipsInfo(
55 1
            $incomingShip,
56 1
            $battleParties,
57 1
            $informations
58 1
        );
59
60 1
        return $battleParties;
61
    }
62
}
63