Passed
Push — dev ( 91186a...20d5e2 )
by Janko
05:17
created

SubspaceSystemData::getAnalyzeTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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