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

AttackingBattleParty::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
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\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