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

FlightDirectionConsequence::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Movement\Route\UpdateFlightDirectionInterface;
13
use Stu\Module\Ship\Lib\ShipWrapperInterface;
14
use Stu\Orm\Entity\StarSystemMapInterface;
15
16
class FlightDirectionConsequence extends AbstractFlightConsequence
17
{
18
    private UpdateFlightDirectionInterface $updateFlightDirection;
19
20 5
    public function __construct(
21
        UpdateFlightDirectionInterface $updateFlightDirection
22
    ) {
23 5
        $this->updateFlightDirection = $updateFlightDirection;
24
    }
25
26 3
    protected function triggerSpecific(
27
        ShipWrapperInterface $wrapper,
28
        FlightRouteInterface $flightRoute,
29
        MessageCollectionInterface $messages
30
    ): void {
31
32 3
        $ship = $wrapper->get();
33
34
        //leaving star system
35 3
        if ($flightRoute->getRouteMode() === RouteModeEnum::ROUTE_MODE_SYSTEM_EXIT) {
36 2
            $oldWaypoint = $ship->getCurrentMapField();
37 2
            if (!$oldWaypoint instanceof StarSystemMapInterface) {
38 1
                throw new RuntimeException('this should not happen');
39
            }
40
41 1
            $this->updateFlightDirection->updateWhenSystemExit($ship, $oldWaypoint);
42
        }
43
    }
44
}
45