Passed
Pull Request — master (#1819)
by Nico
52:14 queued 25:19
created

AttackingBattleParty::initMembers()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
nc 3
nop 0
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 4
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\Module\Ship\Lib\FleetWrapperInterface;
7
use Stu\Module\Ship\Lib\ShipWrapperInterface;
8
9
class AttackingBattleParty extends AbstractBattleParty
10
{
11 4
    public function __construct(
12
        private ShipWrapperInterface|FleetWrapperInterface $wrapper
13
    ) {
14 4
        $leader = $wrapper instanceof ShipWrapperInterface ? $wrapper : $wrapper->getLeadWrapper();
15
16 4
        parent::__construct($leader);
17
    }
18
19 4
    public function initMembers(): Collection
20
    {
21 4
        if ($this->wrapper instanceof FleetWrapperInterface) {
22 1
            return $this->wrapper->getShipWrappers();
23
        }
24
25 3
        $ship = $this->wrapper->get();
26 3
        $fleetWrapper = $this->wrapper->getFleetWrapper();
27
28 3
        if ($ship->isFleetLeader() && $fleetWrapper !== null) {
29 1
            return $fleetWrapper->getShipWrappers();
30
        } else {
31 2
            return $this->createSingleton($this->wrapper);
32
        }
33
    }
34
}
35