Passed
Push — dev ( 302539...72decd )
by Janko
05:12
created

LifeSupportCheckHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 24
ccs 6
cts 9
cp 0.6667
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleSpacecraftTick() 0 17 3
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
13
class LifeSupportCheckHandler implements SpacecraftTickHandlerInterface
14
{
15 1
    public function __construct(
16
        private readonly CrewAssignmentRepositoryInterface $crewAssignmentRepository,
17
        private readonly SpacecraftLeaverInterface $spacecraftLeaver
18 1
    ) {}
19
20 1
    #[Override]
21
    public function handleSpacecraftTick(
22
        SpacecraftWrapperInterface $wrapper,
23
        InformationInterface $information
24
    ): void {
25
26 1
        $spacecraft = $wrapper->get();
27
28
        // leave spacecraft
29
        if (
30 1
            $this->crewAssignmentRepository->getAmountBySpacecraft($spacecraft) > 0
31 1
            && !$spacecraft->isSystemHealthy(SpacecraftSystemTypeEnum::LIFE_SUPPORT)
32
        ) {
33
            $information->addInformation('Die Lebenserhaltung ist ausgefallen:');
34
            $information->addInformation($this->spacecraftLeaver->evacuate($wrapper));
35
36
            throw new SpacecraftTickFinishedException();
37
        }
38
    }
39
}
40