Passed
Push — dev ( 7dee43...836565 )
by Nico
06:34
created

LifeSupportCheckHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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