Test Failed
Push — dev ( 0a21cd...88787c )
by Janko
08:43
created

WarpDriveSystemData   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Test Coverage

Coverage 46.43%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 73
dl 0
loc 190
ccs 39
cts 84
cp 0.4643
rs 10
c 1
b 1
f 0
wmc 30

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllPossibleRumps() 0 19 6
A getAutoCarryOver() 0 3 1
A setWarpSignature() 0 4 1
A setWarpDriveSplit() 0 4 1
A getWarpDriveStatusBar() 0 9 1
A getWarpDriveStatusBarBig() 0 10 1
A setWarpSignatureTimer() 0 4 1
A getWarpSignatureTimer() 0 3 1
A getWarpSignature() 0 3 1
A lowerWarpDrive() 0 4 1
A __construct() 0 13 1
A getWarpDrive() 0 3 1
A getSystemType() 0 4 1
A setWarpDrive() 0 4 1
A getTheoreticalMaxWarpdrive() 0 3 1
A getWarpDriveSplit() 0 3 1
A update() 0 6 1
A isWarpSignatureActive() 0 3 2
A setAutoCarryOver() 0 4 1
A setMaxWarpDrive() 0 4 1
A getWarpdrivePercentage() 0 13 3
A getMaxWarpdrive() 0 4 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\Module\Control\StuTime;
9
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
10
use Stu\Module\Template\StatusBarColorEnum;
11
use Stu\Orm\Repository\SpacecraftRumpRepositoryInterface;
12
use Stu\Orm\Repository\DatabaseUserRepositoryInterface;
13
use Stu\Module\Control\GameController;
14
use Stu\Orm\Entity\SpacecraftRump;
15
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
16
use Stu\Module\Template\StatusBarFactoryInterface;
17
18
class WarpDriveSystemData extends AbstractSystemData
19
{
20
    // warpdrive fields
21
    public int $wd = 0;
22
    public int $maxwd = 0;
23
    public int $split = 100;
24
    public bool $autoCarryOver = false;
25
    public int $warpsignature = 0;
26
    public int $wstimer = 0;
27
28
    private StuTime $stuTime;
29
    private SpacecraftRumpRepositoryInterface $rumpRepository;
30
    private DatabaseUserRepositoryInterface $databaseUserRepository;
31
    private GameController $game;
32
33 5
    public function __construct(
34
        SpacecraftSystemRepositoryInterface $shipSystemRepository,
35
        StatusBarFactoryInterface $statusBarFactory,
36
        StuTime $stuTime,
37
        SpacecraftRumpRepositoryInterface $rumpRepository,
38
        DatabaseUserRepositoryInterface $databaseUserRepository,
39
        GameController $game
40
    ) {
41 5
        parent::__construct($shipSystemRepository, $statusBarFactory);
42 5
        $this->stuTime = $stuTime;
43 5
        $this->rumpRepository = $rumpRepository;
44 5
        $this->databaseUserRepository = $databaseUserRepository;
45 5
        $this->game = $game;
46
    }
47
48
    #[Override]
49
    public function getSystemType(): SpacecraftSystemTypeEnum
50
    {
51
        return SpacecraftSystemTypeEnum::WARPDRIVE;
52
    }
53
54
    #[Override]
55
    public function update(): void
56
    {
57
        $this->split = max(0, min(100, $this->split));
58
59
        parent::update();
60
    }
61
62
    /**
63
     * @return array<SpacecraftRump>
64
     */
65 1
    public function getAllPossibleRumps(): array
66
    {
67 1
        $userId = $this->game->getUser()->getId();
68
69 1
        $allRumps = $this->rumpRepository->getList();
70
71 1
        $possibleRumps = [];
72
73 1
        foreach ($allRumps as $rump) {
74 1
            if (!$rump->getIsNpc() && $rump->getDatabaseId() !== null && ($rump->getCategoryId()->value < 9)) {
75 1
                if ($this->databaseUserRepository->exists($userId, $rump->getDatabaseId())) {
76 1
                    $possibleRumps[$rump->getId()] = $rump;
77
                }
78
            }
79
        }
80
81 1
        ksort($possibleRumps);
82
83 1
        return array_values($possibleRumps);
84
    }
85
86 5
    public function getWarpDrive(): int
87
    {
88 5
        return $this->wd;
89
    }
90
91
    public function setWarpDrive(int $wd): WarpDriveSystemData
92
    {
93
        $this->wd = $wd;
94
        return $this;
95
    }
96
97
    public function lowerWarpDrive(int $amount): WarpDriveSystemData
98
    {
99
        $this->wd -= $amount;
100
        return $this;
101
    }
102
103
    public function setMaxWarpDrive(int $maxwd): WarpDriveSystemData
104
    {
105
        $this->maxwd = $maxwd;
106
        return $this;
107
    }
108
109
    public function getTheoreticalMaxWarpdrive(): int
110
    {
111
        return $this->maxwd;
112
    }
113
114
    /**
115
     * proportional to warpdrive system status
116
     */
117 5
    public function getMaxWarpdrive(): int
118
    {
119 5
        return (int) (ceil($this->maxwd
120 5
            * $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE)->getStatus() / 100));
121
    }
122
123 3
    public function getWarpDriveSplit(): int
124
    {
125 3
        return $this->split;
126
    }
127
128
    public function setWarpDriveSplit(int $split): WarpDriveSystemData
129
    {
130
        $this->split = $split;
131
        return $this;
132
    }
133
134 3
    public function getAutoCarryOver(): bool
135
    {
136 3
        return $this->autoCarryOver;
137
    }
138
139
    public function setAutoCarryOver(bool $autoCarryOver): WarpDriveSystemData
140
    {
141
        $this->autoCarryOver = $autoCarryOver;
142
        return $this;
143
    }
144
145
    public function getWarpdrivePercentage(): int
146
    {
147
        $currentWarpdrive = $this->getWarpDrive();
148
        $maxWarpdrive = $this->getMaxWarpdrive();
149
150
        if ($currentWarpdrive === 0) {
151
            return 0;
152
        }
153
        if ($maxWarpdrive === 0) {
154
            return 100;
155
        }
156
157
        return (int)floor($currentWarpdrive / $maxWarpdrive * 100);
158
    }
159
160 2
    public function getWarpDriveStatusBar(): string
161
    {
162 2
        return $this->getStatusBar(
163 2
            _('Warpantrieb'),
164 2
            $this->getWarpDrive(),
165 2
            $this->getMaxWarpdrive(),
166 2
            StatusBarColorEnum::BLUE
167 2
        )
168 2
            ->render();
169
    }
170
171
    public function getWarpDriveStatusBarBig(): string
172
    {
173
        return $this->getStatusBar(
174
            _('Warpantrieb'),
175
            $this->getWarpDrive(),
176
            $this->getMaxWarpdrive(),
177
            StatusBarColorEnum::BLUE
178
        )
179
            ->setSizeModifier(1.6)
180
            ->render();
181
    }
182
183 1
    public function getWarpSignature(): int
184
    {
185 1
        return $this->warpsignature;
186
    }
187
188
    public function setWarpSignature(int $warpsignature): WarpDriveSystemData
189
    {
190
        $this->warpsignature = $warpsignature;
191
        return $this;
192
    }
193
194 1
    public function getWarpSignatureTimer(): int
195
    {
196 1
        return $this->wstimer;
197
    }
198
199
    public function setWarpSignatureTimer(int $wstimer): WarpDriveSystemData
200
    {
201
        $this->wstimer = $wstimer;
202
        return $this;
203
    }
204
205 1
    public function isWarpSignatureActive(): bool
206
    {
207 1
        return $this->getWarpSignature() > 0 && $this->getWarpSignatureTimer() + 300 >= $this->stuTime->time();
208
    }
209
}
210