Passed
Push — master ( 91454b...2408fc )
by Nico
22:07 queued 10:43
created

SpacecraftShutdown::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 5
dl 0
loc 7
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib\Auxiliary;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Stu\Component\Spacecraft\SpacecraftStateEnum;
9
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface;
10
use Stu\Module\Ship\Lib\Fleet\LeaveFleetInterface;
11
use Stu\Module\Spacecraft\Lib\Interaction\ShipUndockingInterface;
12
use Stu\Module\Spacecraft\Lib\SpacecraftStateChangerInterface;
13
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
14
use Stu\Orm\Entity\ShipInterface;
15
use Stu\Orm\Entity\StationInterface;
16
use Stu\Orm\Repository\SpacecraftRepositoryInterface;
17
18
final class SpacecraftShutdown implements SpacecraftShutdownInterface
19
{
20 8
    public function __construct(
21
        private SpacecraftRepositoryInterface $spacecraftRepository,
22
        private SpacecraftSystemManagerInterface $spacecraftSystemManager,
23
        private LeaveFleetInterface $leaveFleet,
24
        private SpacecraftStateChangerInterface $spacecraftStateChanger,
25
        private ShipUndockingInterface $shipUndocking
26 8
    ) {}
27
28 7
    #[Override]
29
    public function shutdown(SpacecraftWrapperInterface $wrapper, bool $doLeaveFleet = false): void
30
    {
31 7
        $this->spacecraftSystemManager->deactivateAll($wrapper);
32
33 7
        $spacecraft = $wrapper->get();
34
35 7
        if ($doLeaveFleet && $spacecraft instanceof ShipInterface) {
36 1
            $this->leaveFleet->leaveFleet($spacecraft);
37
        }
38 7
        if ($spacecraft instanceof StationInterface) {
39 4
            $this->shipUndocking->undockAllDocked($spacecraft);
40
        }
41 7
        if ($spacecraft->getState()->isActiveState()) {
42 6
            $this->spacecraftStateChanger->changeState($wrapper, SpacecraftStateEnum::NONE);
43
        }
44
45 7
        $spacecraft->setAlertStateGreen();
46 7
        $this->spacecraftRepository->save($spacecraft);
47
    }
48
}
49