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

AlertStateBattleParty::getAttackCause()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Battle\Party;
4
5
use Doctrine\Common\Collections\Collection;
6
use Stu\Component\Ship\ShipAlertStateEnum;
7
use Stu\Module\Ship\Lib\Battle\ShipAttackCauseEnum;
8
use Stu\Module\Ship\Lib\ShipWrapperInterface;
9
10
class AlertStateBattleParty extends AbstractBattleParty implements AlertedBattlePartyInterface
11
{
12
    private ShipAlertStateEnum $leaderAlertState;
13
    private bool $isSingleton = false;
14
15 2
    public function __construct(
16
        ShipWrapperInterface $leader
17
    ) {
18 2
        parent::__construct($leader);
19
20 2
        $this->leaderAlertState = $leader->get()->getAlertState();
21
    }
22
23 2
    public function initMembers(): Collection
24
    {
25 2
        $fleet = $this->leader->getFleetWrapper();
26
27 2
        if ($fleet === null) {
28 1
            $this->isSingleton = true;
29 1
            return $this->createSingleton($this->leader);
30
        } else {
31
32
            // only uncloaked and unwarped ships enter fight
33 1
            return $fleet->getShipWrappers()
34 1
                ->filter(fn (ShipWrapperInterface $wrapper) => !$wrapper->get()->getCloakState()
35 1
                    && !$wrapper->get()->isWarped()
36 1
                    && $wrapper->get()->getAlertState()->isAtLeast($this->leaderAlertState));
37
        }
38
    }
39
40
    public function isSingleton(): bool
41
    {
42
        return $this->isSingleton;
43
    }
44
45
    public function getAlertState(): ShipAlertStateEnum
46
    {
47
        return $this->leaderAlertState;
48
    }
49
50
    public function getAttackCause(): ShipAttackCauseEnum
51
    {
52
        return $this->leaderAlertState->getAttackCause();
53
    }
54
55
    public function getAlertDescription(): string
56
    {
57
        return $this->leaderAlertState === ShipAlertStateEnum::ALERT_RED
58
            ? '[b][color=red]Alarm-Rot[/color][/b]'
59
            : '[b][color=yellow]Alarm-Gelb[/color][/b]';
60
    }
61
}
62