Test Failed
Pull Request — dev (#1952)
by Janko
02:59
created

WarpDriveSystemData::setAutoCarryOver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 1
cts 1
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;
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 21
34
    public function getWarpDrive(): int
35
    {
36
        return $this->wd;
37
    }
38
39
    public function setWarpDrive(int $wd): WarpDriveSystemData
40
    {
41 21
        $this->wd = $wd;
42 21
        return $this;
43 21
    }
44 21
45 21
    public function lowerWarpDrive(int $amount): WarpDriveSystemData
46
    {
47
        $this->wd -= $amount;
48 7
        return $this;
49
    }
50
51 7
    public function setMaxWarpDrive(int $maxwd): WarpDriveSystemData
52
    {
53
        $this->maxwd = $maxwd;
54 7
        return $this;
55
    }
56
57 7
    public function getTheoreticalMaxWarpdrive(): int
58
    {
59 7
        return $this->maxwd;
60
    }
61
62
    /**
63
     * proportional to warpdrive system status
64
     */
65 2
    public function getMaxWarpDrive(): int
66
    {
67 2
        return (int) (ceil($this->maxwd
68
            * $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE)->getStatus() / 100));
69 2
    }
70
71 2
    public function getWarpDriveSplit(): int
72
    {
73 2
        return $this->split;
74 2
    }
75 2
76 1
    public function setWarpDriveSplit(int $split): WarpDriveSystemData
77
    {
78
        $this->split = $split;
79
        return $this;
80
    }
81 2
82
    public function getAutoCarryOver(): bool
83 2
    {
84
        return $this->autoCarryOver;
85
    }
86 19
87
    public function setAutoCarryOver(bool $autoCarryOver): WarpDriveSystemData
88 19
    {
89
        $this->autoCarryOver = $autoCarryOver;
90
        return $this;
91 2
    }
92
93 2
    public function getWarpdrivePercentage(): int
94 2
    {
95
        $currentWarpdrive = $this->getWarpDrive();
96
        $maxWarpdrive = $this->getMaxWarpDrive();
97 3
98
        if ($currentWarpdrive === 0) {
99 3
            return 0;
100 3
        }
101
        if ($maxWarpdrive === 0) {
102
            return 100;
103 2
        }
104
105 2
        return (int)floor($currentWarpdrive / $maxWarpdrive * 100);
106 2
    }
107
108
    public function getWarpDriveStatusBar(): string
109
    {
110
        return $this->getStatusBar(
111
            _('Warpantrieb'),
112
            $this->getWarpDrive(),
113
            $this->getMaxWarpDrive(),
114
            StatusBarColorEnum::BLUE
115
        )
116
            ->render();
117 15
    }
118
119 15
    public function getWarpDriveStatusBarBig(): string
120 15
    {
121
        return $this->getStatusBar(
122
            _('Warpantrieb'),
123 6
            $this->getWarpDrive(),
124
            $this->getMaxWarpDrive(),
125 6
            StatusBarColorEnum::BLUE
126
        )
127
            ->setSizeModifier(1.6)
128 1
            ->render();
129
    }
130
}
131