Passed
Push — dev ( 4911cc...5f893c )
by Nico
16:39
created

WarpDriveSystemData::getWarpDriveStatusBar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 1
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\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 WarpDriveSystemData extends AbstractSystemData
12
{
13
    // warpdrive fields
14
    public int $wd = 0;
15
    public int $maxwd = 0;
16
    public int $split = 100;
17
    public bool $autoCarryOver = false;
18
19
    #[Override]
20
    public function getSystemType(): SpacecraftSystemTypeEnum
21
    {
22
        return SpacecraftSystemTypeEnum::WARPDRIVE;
23
    }
24
25
    #[Override]
26
    public function update(): void
27
    {
28
        // Überprüfe und begrenze den Wert zwischen 0 und 100
29
        $this->split = max(0, min(100, $this->split));
30
31
        parent::update();
32
    }
33
34 5
    public function getWarpDrive(): int
35
    {
36 5
        return $this->wd;
37
    }
38
39
    public function setWarpDrive(int $wd): WarpDriveSystemData
40
    {
41
        $this->wd = $wd;
42
        return $this;
43
    }
44
45
    public function lowerWarpDrive(int $amount): WarpDriveSystemData
46
    {
47
        $this->wd -= $amount;
48
        return $this;
49
    }
50
51
    public function setMaxWarpDrive(int $maxwd): WarpDriveSystemData
52
    {
53
        $this->maxwd = $maxwd;
54
        return $this;
55
    }
56
57
    public function getTheoreticalMaxWarpdrive(): int
58
    {
59
        return $this->maxwd;
60
    }
61
62
    /**
63
     * proportional to warpdrive system status
64
     */
65 5
    public function getMaxWarpDrive(): int
66
    {
67 5
        return (int) (ceil($this->maxwd
68 5
            * $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE)->getStatus() / 100));
69
    }
70
71 3
    public function getWarpDriveSplit(): int
72
    {
73 3
        return $this->split;
74
    }
75
76
    public function setWarpDriveSplit(int $split): WarpDriveSystemData
77
    {
78
        $this->split = $split;
79
        return $this;
80
    }
81
82 3
    public function getAutoCarryOver(): bool
83
    {
84 3
        return $this->autoCarryOver;
85
    }
86
87
    public function setAutoCarryOver(bool $autoCarryOver): WarpDriveSystemData
88
    {
89
        $this->autoCarryOver = $autoCarryOver;
90
        return $this;
91
    }
92
93
    public function getWarpdrivePercentage(): int
94
    {
95
        $currentWarpdrive = $this->getWarpDrive();
96
        $maxWarpdrive = $this->getMaxWarpDrive();
97
98
        if ($currentWarpdrive === 0) {
99
            return 0;
100
        }
101
        if ($maxWarpdrive === 0) {
102
            return 100;
103
        }
104
105
        return (int)floor($currentWarpdrive / $maxWarpdrive * 100);
106
    }
107
108 2
    public function getWarpDriveStatusBar(): string
109
    {
110 2
        return $this->getStatusBar(
111 2
            _('Warpantrieb'),
112 2
            $this->getWarpDrive(),
113 2
            $this->getMaxWarpDrive(),
114 2
            StatusBarColorEnum::STATUSBAR_BLUE
115 2
        )
116 2
            ->render();
117
    }
118
119
    public function getWarpDriveStatusBarBig(): string
120
    {
121
        return $this->getStatusBar(
122
            _('Warpantrieb'),
123
            $this->getWarpDrive(),
124
            $this->getMaxWarpDrive(),
125
            StatusBarColorEnum::STATUSBAR_BLUE
126
        )
127
            ->setSizeModifier(1.6)
128
            ->render();
129
    }
130
}
131