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

LeaveStarSystem::getFlightRoute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 16
ccs 0
cts 9
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\LeaveStarSystem;
6
7
use RuntimeException;
8
use Stu\Module\Control\GameControllerInterface;
9
use Stu\Module\Ship\Action\MoveShip\AbstractDirectedMovement;
10
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface;
11
use Stu\Module\Ship\Lib\ShipWrapperInterface;
12
13
final class LeaveStarSystem extends AbstractDirectedMovement
14
{
15
    public const ACTION_IDENTIFIER = 'B_LEAVE_STARSYSTEM';
16
17
    protected function isSanityCheckFaultyConcrete(ShipWrapperInterface $wrapper, GameControllerInterface $game): bool
18
    {
19
        $ship = $wrapper->get();
20
21
        $starsystemMap = $ship->getStarsystemMap();
22
        if ($starsystemMap === null) {
23
            return true;
24
        }
25
26
        //the destination map field
27
        $outerMap = $starsystemMap->getSystem()->getMapField();
28
        if ($outerMap === null) {
29
            return true;
30
        }
31
32
        return false;
33
    }
34
35
    protected function getFlightRoute(ShipWrapperInterface $wrapper): FlightRouteInterface
36
    {
37
        $ship = $wrapper->get();
38
39
        $starsystemMap = $ship->getStarsystemMap();
40
        if ($starsystemMap === null) {
41
            throw new RuntimeException('should not happen');
42
        }
43
44
        //the destination map field
45
        $destination = $starsystemMap->getSystem()->getMapField();
46
        if ($destination === null) {
47
            throw new RuntimeException('should not happen');
48
        }
49
50
        return $this->flightRouteFactory->getRouteForMapDestination($destination);
51
    }
52
}
53