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

WarpdriveConsequence   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 33
ccs 15
cts 16
cp 0.9375
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A triggerSpecific() 0 31 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Movement\Component\Consequence\Flight;
6
7
use RuntimeException;
8
use Stu\Module\Ship\Lib\Message\MessageCollectionInterface;
9
use Stu\Module\Ship\Lib\Movement\Component\Consequence\AbstractFlightConsequence;
10
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface;
11
use Stu\Module\Ship\Lib\Movement\Route\RouteModeEnum;
12
use Stu\Module\Ship\Lib\ShipWrapperInterface;
13
use Stu\Orm\Entity\StarSystemMapInterface;
14
15
class WarpdriveConsequence extends AbstractFlightConsequence
16
{
17 9
    protected function triggerSpecific(
18
        ShipWrapperInterface $wrapper,
19
        FlightRouteInterface $flightRoute,
20
        MessageCollectionInterface $messages
21
    ): void {
22 9
        if ($wrapper->get()->isTractored()) {
23 1
            return;
24
        }
25
26 8
        $routeMode = $flightRoute->getRouteMode();
27 8
        if ($routeMode !== RouteModeEnum::ROUTE_MODE_FLIGHT) {
28 5
            return;
29
        }
30
31 3
        if ($flightRoute->getNextWaypoint() instanceof StarSystemMapInterface) {
32 1
            return;
33
        }
34
35 2
        $warpdriveSystem = $wrapper->getWarpDriveSystemData();
36 2
        if ($warpdriveSystem === null) {
37
            throw new RuntimeException('this should not happen');
38
        }
39
40 2
        $ship = $wrapper->get();
41
42 2
        $neededWarpDrive = 1;
43 2
        if ($ship->isTractoring()) {
44 1
            $neededWarpDrive += 2;
45
        }
46
47 2
        $warpdriveSystem->lowerWarpDrive($neededWarpDrive)->update();
48
    }
49
}
50