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

AlertedShipsDetection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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