Passed
Push — master ( f4068b...77f637 )
by Nico
40:27 queued 14:09
created

ShipShutdown   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
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 39
ccs 15
cts 15
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A shutdown() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Auxiliary;
6
7
use Stu\Component\Ship\ShipStateEnum;
8
use Stu\Component\Ship\System\ShipSystemManagerInterface;
9
use Stu\Module\Ship\Lib\Fleet\LeaveFleetInterface;
10
use Stu\Module\Ship\Lib\Interaction\ShipUndockingInterface;
11
use Stu\Module\Ship\Lib\ShipStateChangerInterface;
12
use Stu\Module\Ship\Lib\ShipWrapperInterface;
13
use Stu\Orm\Repository\ShipRepositoryInterface;
14
15
final class ShipShutdown implements ShipShutdownInterface
16
{
17
    private ShipRepositoryInterface $shipRepository;
18
19
    private ShipSystemManagerInterface $shipSystemManager;
20
21
    private LeaveFleetInterface $leaveFleet;
22
23
    private ShipStateChangerInterface $shipStateChanger;
24
25
    private ShipUndockingInterface $shipUndocking;
26
27 2
    public function __construct(
28
        ShipRepositoryInterface $shipRepository,
29
        ShipSystemManagerInterface $shipSystemManager,
30
        LeaveFleetInterface $leaveFleet,
31
        ShipStateChangerInterface $shipStateChanger,
32
        ShipUndockingInterface $shipUndocking
33
    ) {
34 2
        $this->shipRepository = $shipRepository;
35 2
        $this->shipSystemManager = $shipSystemManager;
36 2
        $this->leaveFleet = $leaveFleet;
37 2
        $this->shipStateChanger = $shipStateChanger;
38 2
        $this->shipUndocking = $shipUndocking;
39
    }
40
41 1
    public function shutdown(ShipWrapperInterface $wrapper): void
42
    {
43 1
        $this->shipSystemManager->deactivateAll($wrapper);
44
45 1
        $ship = $wrapper->get();
46
47 1
        $this->leaveFleet->leaveFleet($ship);
48 1
        $this->shipUndocking->undockAllDocked($ship);
49 1
        $this->shipStateChanger->changeShipState($wrapper, ShipStateEnum::SHIP_STATE_NONE);
50
51 1
        $ship->setAlertStateGreen();
52 1
        $ship->setDockedTo(null);
53 1
        $this->shipRepository->save($ship);
54
    }
55
}
56