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

LeaveStarSystem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 38
ccs 0
cts 18
cp 0
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFlightRoute() 0 16 3
A isSanityCheckFaultyConcrete() 0 16 3
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