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

AlertedShipInformation::addInformation()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
nc 2
nop 6
dl 0
loc 26
ccs 15
cts 15
cp 1
crap 4
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Battle\AlertDetection;
4
5
use Stu\Component\Ship\ShipAlertStateEnum;
6
use Stu\Lib\Information\InformationInterface;
7
use Stu\Module\Ship\Lib\Battle\Party\AlertStateBattleParty;
8
use Stu\Orm\Entity\ShipInterface;
9
10
class AlertedShipInformation implements AlertedShipInformationInterface
11
{
12
13 4
    public function addAlertedShipsInfo(
14
        ShipInterface $incomingShip,
15
        array $alertedBattleParties,
16
        InformationInterface $informations
17
    ): void {
18
19 4
        $this->addInformation(
20 4
            $incomingShip,
21 4
            $alertedBattleParties,
22 4
            ShipAlertStateEnum::ALERT_RED,
23 4
            false,
24 4
            'Flotte(n) auf [b][color=red]Alarm-Rot![/color][/b]',
25 4
            $informations
26 4
        );
27 4
        $this->addInformation(
28 4
            $incomingShip,
29 4
            $alertedBattleParties,
30 4
            ShipAlertStateEnum::ALERT_RED,
31 4
            true,
32 4
            'Einzelschiff(e) auf [b][color=red]Alarm-Rot![/color][/b]',
33 4
            $informations
34 4
        );
35 4
        $this->addInformation(
36 4
            $incomingShip,
37 4
            $alertedBattleParties,
38 4
            ShipAlertStateEnum::ALERT_YELLOW,
39 4
            false,
40 4
            'Flotte(n) auf [b][color=yellow]Alarm-Gelb![/color][/b]',
41 4
            $informations
42 4
        );
43 4
        $this->addInformation(
44 4
            $incomingShip,
45 4
            $alertedBattleParties,
46 4
            ShipAlertStateEnum::ALERT_YELLOW,
47 4
            true,
48 4
            'Einzelschiff(e) auf [b][color=yellow]Alarm-Gelb![/color][/b]',
49 4
            $informations
50 4
        );
51
    }
52
53
    /** @param array<AlertStateBattleParty> $alertedBattleParties */
54 4
    private function addInformation(
55
        ShipInterface $incomingShip,
56
        array $alertedBattleParties,
57
        ShipAlertStateEnum $alertState,
58
        bool $isSingleton,
59
        string $format,
60
        InformationInterface $informations
61
    ): void {
62
63 4
        $count = count(array_filter(
64 4
            $alertedBattleParties,
65 4
            fn (AlertStateBattleParty $battlyParty) => $battlyParty->isSingleton() === $isSingleton
66 4
                && $battlyParty->getAlertState() === $alertState
67 4
        ));
68
69 4
        if ($count === 0) {
70 4
            return;
71
        }
72
73 4
        $informations->addInformation(sprintf(
74 4
            _('In Sektor %d|%d %s %d %s') . "\n",
75 4
            $incomingShip->getPosX(),
76 4
            $incomingShip->getPosY(),
77 4
            $count > 1 ? 'befinden sich' : 'befindet sich',
78 4
            $count,
79 4
            $format
80 4
        ));
81
    }
82
}
83