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

AlertedShipsDetection::getAlertedShipsOnLocation()   B

Complexity

Conditions 7
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 9
nc 1
nop 1
dl 0
loc 12
ccs 11
cts 11
cp 1
crap 7
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Battle\AlertDetection;
4
5
use Doctrine\Common\Collections\Collection;
6
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
7
use Stu\Orm\Entity\ShipInterface;
8
9
class AlertedShipsDetection implements AlertedShipsDetectionInterface
10
{
11 9
    public function __construct(
12
        private ShipWrapperFactoryInterface $shipWrapperFactory
13
    ) {
14 9
    }
15
16 9
    public function getAlertedShipsOnLocation(ShipInterface $incomingShip): Collection
17
    {
18 9
        return $incomingShip->getCurrentMapField()->getShips()
19 9
            ->filter(
20 9
                fn (ShipInterface $ship) => !$ship->getUser()->isVacationRequestOldEnough()
21 8
                    && $ship->getUser() !== $incomingShip->getUser()
22 8
                    && ($ship->isFleetLeader() || $ship->getFleet() === null)
23 8
                    && !$ship->isAlertGreen()
24 8
                    && !$ship->isWarped()
25 8
                    && !$ship->getCloakState()
26 9
            )
27 9
            ->map(fn (ShipInterface $ship) => $this->shipWrapperFactory->wrapShip($ship));
28
    }
29
}
30