Passed
Push — dev ( 45bf8d...5b8f46 )
by Janko
10:07
created

AlertStateConsequence::triggerSpecific()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 3
nop 3
dl 0
loc 26
ccs 0
cts 12
cp 0
crap 30
rs 9.5222
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib\Movement\Component\Consequence\Flight;
6
7
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...
8
use Stu\Component\Anomaly\Type\AnomalyTypeEnum;
9
use Stu\Component\Spacecraft\SpacecraftAlertStateEnum;
10
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
11
use Stu\Module\Spacecraft\Lib\ActivatorDeactivatorHelperInterface;
12
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface;
13
use Stu\Module\Spacecraft\Lib\Message\MessageFactoryInterface;
14
use Stu\Module\Spacecraft\Lib\Movement\Component\Consequence\AbstractFlightConsequence;
15
use Stu\Module\Spacecraft\Lib\Movement\Route\FlightRouteInterface;
16
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
17
18
class AlertStateConsequence extends AbstractFlightConsequence implements FlightStartConsequenceInterface
19
{
20 1
    public function __construct(
21
        private ActivatorDeactivatorHelperInterface $activatorDeactivatorHelper,
22
        private MessageFactoryInterface $messageFactory
23 1
    ) {}
24
25
    #[Override]
26
    protected function skipWhenTractored(): bool
27
    {
28
        return true;
29
    }
30
31
    #[Override]
32
    protected function triggerSpecific(
33
        SpacecraftWrapperInterface $wrapper,
34
        FlightRouteInterface $flightRoute,
35
        MessageCollectionInterface $messages
36
    ): void {
37
38
        if (!$flightRoute->getNextWaypoint()->hasAnomaly(AnomalyTypeEnum::ION_STORM)) {
39
            return;
40
        }
41
42
        $spacecraft = $wrapper->get();
43
        $shieldSystem = $spacecraft->getSystems()[SpacecraftSystemTypeEnum::SHIELDS->value] ?? null;
44
45
        if (
46
            $shieldSystem === null
47
            || $shieldSystem->getMode()->isActivated()
48
            || !$spacecraft->getAlertState()->isAtLeast(SpacecraftAlertStateEnum::ALERT_YELLOW)
49
        ) {
50
            return;
51
        }
52
53
        $message = $this->messageFactory->createMessage();
54
        $messages->add($message);
55
56
        $this->activatorDeactivatorHelper->activate($wrapper, SpacecraftSystemTypeEnum::SHIELDS, $message);
57
    }
58
}
59