Passed
Push — master ( 288b46...98b0e3 )
by Nico
31:30 queued 08:00
created

EnoughWarpdriveCondition   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 37
ccs 21
cts 21
cp 1
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B check() 0 35 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Movement\Component\PreFlight\Condition;
6
7
use Stu\Module\Ship\Lib\Movement\Component\PreFlight\ConditionCheckResult;
8
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface;
9
use Stu\Module\Ship\Lib\Movement\Route\RouteModeEnum;
10
use Stu\Module\Ship\Lib\ShipWrapperInterface;
11
use Stu\Orm\Entity\StarSystemMapInterface;
12
13
class EnoughWarpdriveCondition implements PreFlightConditionInterface
14
{
15 18
    public function check(
16
        ShipWrapperInterface $wrapper,
17
        FlightRouteInterface $flightRoute,
18
        ConditionCheckResult $conditionCheckResult
19
    ): void {
20
21 18
        $routeMode = $flightRoute->getRouteMode();
22 18
        if ($routeMode !== RouteModeEnum::ROUTE_MODE_FLIGHT) {
23 10
            return;
24
        }
25
26 8
        if ($flightRoute->getNextWaypoint() instanceof StarSystemMapInterface) {
27 2
            return;
28
        }
29
30 6
        $warpdriveSystem = $wrapper->getWarpDriveSystemData();
31 6
        if ($warpdriveSystem === null) {
32 2
            return;
33
        }
34
35 4
        $ship = $wrapper->get();
36
37 4
        $neededWarpDrive = 1;
38 4
        if ($ship->isTractoring()) {
39 2
            $neededWarpDrive += 2;
40
        }
41
42 4
        if ($warpdriveSystem->getWarpDrive() < $neededWarpDrive) {
43 2
            $conditionCheckResult->addBlockedShip(
44 2
                $ship,
45 2
                sprintf(
46 2
                    'Die %s hat nicht genug Warpantriebsenergie für den %s (%d benötigt)',
47 2
                    $ship->getName(),
48 2
                    $ship->isTractoring() ? 'Traktor-Flug' : 'Flug',
49 2
                    $neededWarpDrive
50 2
                )
51 2
            );
52
        }
53
    }
54
}
55