Passed
Push — master ( eed220...e3ff64 )
by Janko
21:01 queued 11:01
created

SubspaceSystemData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 2
dl 0
loc 5
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
18
    public function __construct(
19
        SpacecraftSystemRepositoryInterface $shipSystemRepository,
20
        StatusBarFactoryInterface $statusBarFactory
21
    ) {
22
        parent::__construct($shipSystemRepository, $statusBarFactory);
23
    }
24
25
    #[Override]
26
    public function getSystemType(): SpacecraftSystemTypeEnum
27
    {
28
        return SpacecraftSystemTypeEnum::SUBSPACE_SCANNER;
29
    }
30
31
    public function getSpacecraftId(): ?int
32
    {
33
        return $this->spacecraftId ?? null;
34
    }
35
36
    public function setSpacecraftId(?int $spacecraftId): SubspaceSystemData
37
    {
38
        $this->spacecraftId = $spacecraftId;
39
        return $this;
40
    }
41
42
    public function getAnalyzeTime(): ?int
43
    {
44
        return $this->analyzeTime ?? null;
45
    }
46
47
    public function setAnalyzeTime(?int $analyzeTime): SubspaceSystemData
48
    {
49
        $this->analyzeTime = $analyzeTime;
50
        return $this;
51
    }
52
53
    public function getHighlightedSpacecraftId(Spacecraft $spacecraft): ?int
54
    {
55
        $isSubspaceScannerActive = $spacecraft->getSystemState(SpacecraftSystemTypeEnum::SUBSPACE_SCANNER);
56
        if (!$isSubspaceScannerActive) {
57
            return null;
58
        }
59
60
        $isMatrixScannerHealthy = $spacecraft->isSystemHealthy(SpacecraftSystemTypeEnum::MATRIX_SCANNER);
61
        if (!$isMatrixScannerHealthy) {
62
            return null;
63
        }
64
65
        $subspaceSystem = $spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::SUBSPACE_SCANNER);
66
        if ($subspaceSystem->getData() === null) {
67
            return null;
68
        }
69
70
        $analyzeTime = $this->getAnalyzeTime();
71
        if ($analyzeTime === null) {
72
            return null;
73
        }
74
75
        $currentTime = time();
76
        $minTime = $analyzeTime + (3 * 60);
77
        $maxTime = $analyzeTime + (10 * 60);
78
79
        if (!($currentTime >= $minTime && $currentTime <= $maxTime)) {
80
            return null;
81
        }
82
83
        return $this->getSpacecraftId();
84
    }
85
}
86