Passed
Push — master ( 6d8b29...d7e053 )
by Janko
27:40
created

PrestigeCalculation::targetHasPositivePrestige()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 3
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Prestige\Lib;
4
5
use Stu\Module\Ship\Lib\Battle\Party\BattlePartyInterface;
6
use Stu\Module\Ship\Lib\ShipWrapperInterface;
7
use Stu\Orm\Entity\ShipInterface;
8
9
class PrestigeCalculation implements PrestigeCalculationInterface
10
{
11
12 3
    public function getPrestigeOfSpacecraftOrFleet(ShipWrapperInterface|ShipInterface $spacecraft): int
13
    {
14 3
        $target = $spacecraft instanceof ShipInterface ? $spacecraft : $spacecraft->get();
15
16 3
        $fleet = $target->getFleet();
17 3
        if ($fleet !== null) {
18 1
            return array_reduce(
19 1
                $fleet->getShips()->toArray(),
20 1
                fn(int $value, ShipInterface $fleetShip): int => $value + $fleetShip->getRump()->getPrestige(),
21 1
                0
22 1
            );
23
        }
24
25 2
        return $target->getRump()->getPrestige();
26
    }
27
28 3
    public function targetHasPositivePrestige(ShipInterface $target): bool
29
    {
30 3
        $fleet = $target->getFleet();
31 3
        if ($fleet !== null) {
32 1
            foreach ($fleet->getShips() as $ship) {
33 1
                if ($ship->getRump()->getPrestige() > 0) {
34 1
                    return true;
35
                }
36
            }
37
        }
38
39 2
        return $target->getRump()->getPrestige() > 0;
40
    }
41
42 1
    public function getPrestigeOfBattleParty(BattlePartyInterface $battleParty): int
43
    {
44 1
        return $battleParty->getActiveMembers()
45 1
            ->map(fn(ShipWrapperInterface $wrapper) => $wrapper->get()->getRump()->getPrestige())
46 1
            ->reduce(
47 1
                fn(int $sum, int $prestige) => $sum + $prestige,
48 1
                0
49 1
            );
50
    }
51
}
52