Passed
Push — dev ( 996fbb...25004f )
by Janko
16:40
created

EpsSystemData   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Test Coverage

Coverage 82.54%

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 135
ccs 52
cts 63
cp 0.8254
rs 10
c 0
b 0
f 0
wmc 20

18 Methods

Rating   Name   Duplication   Size   Complexity  
A setEps() 0 4 1
A getTheoreticalMaxEps() 0 3 1
A getEps() 0 3 1
A setMaxEps() 0 5 1
A lowerEps() 0 4 1
A getSystemType() 0 4 1
A getEpsStatusBar() 0 9 1
A getMaxBattery() 0 3 1
A getMaxEps() 0 4 1
A setReloadBattery() 0 4 1
A isEBattUseable() 0 3 1
A getBatteryCooldown() 0 3 1
A getBattery() 0 3 1
A getEpsPercentage() 0 13 3
A setBatteryCooldown() 0 4 1
A reloadBattery() 0 3 1
A setBattery() 0 4 1
A getEpsStatusBarBig() 0 10 1
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\StatusBarColorEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Template\StatusBarColorEnum 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...
10
11
class EpsSystemData extends AbstractSystemData
12
{
13
    // eps fields
14
    public int $eps = 0;
15
    public int $maxEps = 0;
16
17
    // battery fields
18
    public int $maxBattery = 0;
19
    public int $battery = 0;
20
    public int $batteryCooldown = 0;
21
    public bool $reloadBattery = false;
22
23 1
    #[Override]
24
    public function getSystemType(): SpacecraftSystemTypeEnum
25
    {
26 1
        return SpacecraftSystemTypeEnum::EPS;
27
    }
28
29 13
    public function getEps(): int
30
    {
31 13
        return $this->eps;
32
    }
33
34 1
    public function setEps(int $eps): EpsSystemData
35
    {
36 1
        $this->eps = $eps;
37 1
        return $this;
38
    }
39
40 1
    public function lowerEps(int $amount): EpsSystemData
41
    {
42 1
        $this->eps -= $amount;
43 1
        return $this;
44
    }
45
46 1
    public function setMaxEps(int $maxEps): EpsSystemData
47
    {
48 1
        $this->maxEps = $maxEps;
49 1
        $this->maxBattery = (int) round($maxEps / 3);
50 1
        return $this;
51
    }
52
53 2
    public function getTheoreticalMaxEps(): int
54
    {
55 2
        return $this->maxEps;
56
    }
57
58
    /**
59
     * proportional to eps system status
60
     */
61 10
    public function getMaxEps(): int
62
    {
63 10
        return (int) (ceil($this->maxEps
64 10
            * $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::EPS)->getStatus() / 100));
65
    }
66
67 6
    public function getMaxBattery(): int
68
    {
69 6
        return $this->maxBattery;
70
    }
71
72 6
    public function getBattery(): int
73
    {
74 6
        return $this->battery;
75
    }
76
77
    public function setBattery(int $battery): EpsSystemData
78
    {
79
        $this->battery = $battery;
80
        return $this;
81
    }
82
83 2
    public function getBatteryCooldown(): int
84
    {
85 2
        return $this->batteryCooldown;
86
    }
87
88
    public function setBatteryCooldown(int $batteryCooldown): EpsSystemData
89
    {
90
        $this->batteryCooldown = $batteryCooldown;
91
        return $this;
92
    }
93
94 2
    public function reloadBattery(): bool
95
    {
96 2
        return $this->reloadBattery;
97
    }
98
99
    public function setReloadBattery(bool $reloadBattery): EpsSystemData
100
    {
101
        $this->reloadBattery = $reloadBattery;
102
        return $this;
103
    }
104
105 3
    public function isEBattUseable(): bool
106
    {
107 3
        return $this->batteryCooldown < time();
108
    }
109
110 1
    public function getEpsPercentage(): int
111
    {
112 1
        $currentEps = $this->getEps();
113 1
        $maxEps = $this->getMaxEps();
114
115 1
        if ($currentEps === 0) {
116
            return 0;
117
        }
118 1
        if ($maxEps === 0) {
119
            return 100;
120
        }
121
122 1
        return (int)floor($currentEps / $maxEps * 100);
123
    }
124
125 3
    public function getEpsStatusBar(): string
126
    {
127 3
        return $this->getStatusBar(
128 3
            _('Energie'),
129 3
            $this->getEps(),
130 3
            $this->getMaxEps(),
131 3
            StatusBarColorEnum::STATUSBAR_YELLOW
132 3
        )
133 3
            ->render();
134
    }
135
136 2
    public function getEpsStatusBarBig(): string
137
    {
138 2
        return $this->getStatusBar(
139 2
            _('Energie'),
140 2
            $this->getEps(),
141 2
            $this->getMaxEps(),
142 2
            StatusBarColorEnum::STATUSBAR_YELLOW
143 2
        )
144 2
            ->setSizeModifier(1.6)
145 2
            ->render();
146
    }
147
}
148