Passed
Pull Request — master (#2125)
by Janko
22:31 queued 12:08
created

LifeSupportCheckHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Stu\Module\Tick\Spacecraft\Handler;
4
5
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...
6
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
7
use Stu\Lib\Information\InformationInterface;
8
use Stu\Module\Spacecraft\Lib\Crew\SpacecraftLeaverInterface;
9
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
10
use Stu\Module\Tick\Spacecraft\SpacecraftTickFinishedException;
11
use Stu\Orm\Repository\CrewAssignmentRepositoryInterface;
12
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
13
14
class LifeSupportCheckHandler implements SpacecraftTickHandlerInterface
15
{
16 1
    public function __construct(
17
        private readonly CrewAssignmentRepositoryInterface $crewAssignmentRepository,
18
        private readonly SpacecraftSystemRepositoryInterface $spacecraftSystemRepository,
19
        private readonly SpacecraftLeaverInterface $spacecraftLeaver
20 1
    ) {}
21
22
    #[Override]
23
    public function handleSpacecraftTick(
24
        SpacecraftWrapperInterface $wrapper,
25
        InformationInterface $information
26
    ): void {
27
28
        $spacecraft = $wrapper->get();
29
30
        // leave spacecraft
31
        if (
32
            $this->crewAssignmentRepository->getAmountBySpacecraft($spacecraft)
33
            && !$this->spacecraftSystemRepository->isSystemHealthy($spacecraft, SpacecraftSystemTypeEnum::LIFE_SUPPORT)
34
        ) {
35
            $information->addInformation('Die Lebenserhaltung ist ausgefallen:');
36
            $information->addInformation($this->spacecraftLeaver->evacuate($wrapper));
37
38
            throw new SpacecraftTickFinishedException();
39
        }
40
    }
41
}
42