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

PostFlightDirectionConsequence   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 40
ccs 19
cts 19
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A triggerSpecific() 0 26 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Movement\Component\Consequence\PostFlight;
6
7
use Stu\Module\Ship\Lib\Message\MessageCollectionInterface;
8
use Stu\Module\Ship\Lib\Movement\Component\Consequence\AbstractFlightConsequence;
9
use Stu\Module\Ship\Lib\Movement\Component\FlightSignatureCreatorInterface;
10
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface;
11
use Stu\Module\Ship\Lib\Movement\Route\UpdateFlightDirectionInterface;
12
use Stu\Module\Ship\Lib\ShipWrapperInterface;
13
14
class PostFlightDirectionConsequence extends AbstractFlightConsequence
15
{
16
    private FlightSignatureCreatorInterface $flightSignatureCreator;
17
18
    private UpdateFlightDirectionInterface $updateFlightDirection;
19
20 5
    public function __construct(
21
        FlightSignatureCreatorInterface $flightSignatureCreator,
22
        UpdateFlightDirectionInterface $updateFlightDirection
23
    ) {
24 5
        $this->flightSignatureCreator = $flightSignatureCreator;
25 5
        $this->updateFlightDirection = $updateFlightDirection;
26
    }
27
28 3
    protected function triggerSpecific(
29
        ShipWrapperInterface $wrapper,
30
        FlightRouteInterface $flightRoute,
31
        MessageCollectionInterface $messages
32
    ): void {
33
34 3
        $ship = $wrapper->get();
35
36 3
        if ($flightRoute->isTraversing()) {
37
38 2
            $oldWaypoint = $flightRoute->getCurrentWaypoint();
39 2
            $waypoint = $flightRoute->getNextWaypoint();
40
41 2
            $flightDirection = $this->updateFlightDirection->updateWhenTraversing(
42 2
                $oldWaypoint,
43 2
                $waypoint,
44 2
                $ship
45 2
            );
46
47
            //create flight signatures
48 2
            if (!$wrapper->get()->isTractored()) {
49 1
                $this->flightSignatureCreator->createSignatures(
50 1
                    $ship,
51 1
                    $flightDirection,
52 1
                    $oldWaypoint,
53 1
                    $waypoint,
54 1
                );
55
            }
56
        }
57
    }
58
}
59