Passed
Pull Request — dev (#2304)
by
unknown
05:16
created

LifeSupportCheckHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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