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

AlertStateBattleParty   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 54.55%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 50
ccs 12
cts 22
cp 0.5455
rs 10
c 1
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initMembers() 0 14 4
A isSingleton() 0 3 1
A __construct() 0 6 1
A getAlertState() 0 3 1
A getAlertDescription() 0 5 2
A getAttackCause() 0 3 1
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