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

ShipShutdown::shutdown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 1
rs 10
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