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

AlertedShipsDetection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getAlertedShipsOnLocation() 0 12 7
A __construct() 0 3 1
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