Passed
Push — master ( 41c1e2...7e39ad )
by Nico
17:44 queued 08:39
created

SubspaceSystemData::getFlightSigId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Spacecraft\System\Data;
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\Spacecraft\System\SpacecraftSystemTypeEnum;
9
use Stu\Module\Template\StatusBarFactoryInterface;
10
use Stu\Orm\Entity\Spacecraft;
11
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
12
13
class SubspaceSystemData extends AbstractSystemData
14
{
15
    public ?int $spacecraftId = null;
16
    public ?int $analyzeTime = null;
17
    public ?int $flightSigId = null;
18
19
    public function __construct(
20
        SpacecraftSystemRepositoryInterface $shipSystemRepository,
21
        StatusBarFactoryInterface $statusBarFactory
22
    ) {
23
        parent::__construct($shipSystemRepository, $statusBarFactory);
24
    }
25
26
    #[Override]
27
    public function getSystemType(): SpacecraftSystemTypeEnum
28
    {
29
        return SpacecraftSystemTypeEnum::SUBSPACE_SCANNER;
30
    }
31
32
    public function getSpacecraftId(): ?int
33
    {
34
        return $this->spacecraftId ?? null;
35
    }
36
37
    public function setSpacecraftId(?int $spacecraftId): SubspaceSystemData
38
    {
39
        $this->spacecraftId = $spacecraftId;
40
        return $this;
41
    }
42
43
    public function getAnalyzeTime(): ?int
44
    {
45
        return $this->analyzeTime ?? null;
46
    }
47
48
    public function setAnalyzeTime(?int $analyzeTime): SubspaceSystemData
49
    {
50
        $this->analyzeTime = $analyzeTime;
51
        return $this;
52
    }
53
54
    public function getFlightSigId(): ?int
55
    {
56
        return $this->flightSigId ?? null;
57
    }
58
59
    public function setFlightSigId(?int $flightSigId): SubspaceSystemData
60
    {
61
        $this->flightSigId = $flightSigId;
62
        return $this;
63
    }
64
65
    public function getHighlightedSpacecraftId(Spacecraft $spacecraft): ?int
66
    {
67
        $isSubspaceScannerActive = $spacecraft->getSystemState(SpacecraftSystemTypeEnum::SUBSPACE_SCANNER);
68
        if (!$isSubspaceScannerActive) {
69
            return null;
70
        }
71
72
        $isMatrixScannerHealthy = $spacecraft->isSystemHealthy(SpacecraftSystemTypeEnum::MATRIX_SCANNER);
73
        if (!$isMatrixScannerHealthy) {
74
            return null;
75
        }
76
77
        $subspaceSystem = $spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::SUBSPACE_SCANNER);
78
        if ($subspaceSystem->getData() === null) {
79
            return null;
80
        }
81
82
        $analyzeTime = $this->getAnalyzeTime();
83
        if ($analyzeTime === null) {
84
            return null;
85
        }
86
87
        $currentTime = time();
88
        $minTime = $analyzeTime + (3 * 60);
89
        $maxTime = $analyzeTime + (10 * 60);
90
91
        if (!($currentTime >= $minTime && $currentTime <= $maxTime)) {
92
            return null;
93
        }
94
95
        return $this->getSpacecraftId();
96
    }
97
}
98