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

LifeSupportCheckHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 22.22%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 25
ccs 2
cts 9
cp 0.2222
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleSpacecraftTick() 0 17 3
A __construct() 0 5 1
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