Passed
Push — dev ( 0dbbcc...f29cfd )
by Janko
10:15
created

SpacecraftSystem::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\Index;
12
use Doctrine\ORM\Mapping\JoinColumn;
13
use Doctrine\ORM\Mapping\ManyToOne;
14
use Doctrine\ORM\Mapping\Table;
15
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...
16
use Stu\Component\Spacecraft\System\SpacecraftSystemModeEnum;
17
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
18
use Stu\Orm\Repository\SpacecraftSystemRepository;
19
20
#[Table(name: 'stu_spacecraft_system')]
21
#[Index(name: 'spacecraft_system_status_idx', columns: ['status'])]
22
#[Index(name: 'spacecraft_system_type_idx', columns: ['system_type'])]
23
#[Index(name: 'spacecraft_system_mode_idx', columns: ['mode'])]
24
#[Entity(repositoryClass: SpacecraftSystemRepository::class)]
25
class SpacecraftSystem implements SpacecraftSystemInterface
26
{
27
    #[Id]
28
    #[Column(type: 'integer')]
29
    #[GeneratedValue(strategy: 'IDENTITY')]
30
    private int $id;
31
32
    #[Column(type: 'integer')]
33
    private int $spacecraft_id = 0;
0 ignored issues
show
introduced by
The private property $spacecraft_id is not used, and could be removed.
Loading history...
34
35
    #[Column(type: 'smallint', enumType: SpacecraftSystemTypeEnum::class)]
36
    private SpacecraftSystemTypeEnum $system_type = SpacecraftSystemTypeEnum::HULL;
37
38
    #[Column(type: 'integer', nullable: true)]
39
    private ?int $module_id = 0;
40
41
    #[Column(type: 'smallint')]
42
    private int $status = 0;
43
44
    #[Column(type: 'smallint', enumType: SpacecraftSystemModeEnum::class)]
45
    private SpacecraftSystemModeEnum $mode = SpacecraftSystemModeEnum::MODE_OFF;
46
47
    #[Column(type: 'integer', nullable: true)]
48
    private ?int $cooldown = null;
49
50
    #[Column(type: 'text', nullable: true)]
51
    private ?string $data = null;
52
53
    #[ManyToOne(targetEntity: 'Module')]
54
    #[JoinColumn(name: 'module_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
55
    private ?ModuleInterface $module = null;
56
57
    #[ManyToOne(targetEntity: 'Spacecraft')]
58
    #[JoinColumn(name: 'spacecraft_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
59
    private SpacecraftInterface $spacecraft;
60
61
    #[Override]
62
    public function getId(): int
63
    {
64
        return $this->id;
65
    }
66
67 4
    #[Override]
68
    public function getSystemType(): SpacecraftSystemTypeEnum
69
    {
70 4
        return $this->system_type;
71
    }
72
73
    #[Override]
74
    public function setSystemType(SpacecraftSystemTypeEnum $type): SpacecraftSystemInterface
75
    {
76
        $this->system_type = $type;
77
78
        return $this;
79
    }
80
81
    #[Override]
82
    public function getModuleId(): ?int
83
    {
84
        return $this->module_id;
85
    }
86
87
    #[Override]
88
    public function setModuleId(int $moduleId): SpacecraftSystemInterface
89
    {
90
        $this->module_id = $moduleId;
91
92
        return $this;
93
    }
94
95 13
    #[Override]
96
    public function getStatus(): int
97
    {
98 13
        return $this->status;
99
    }
100
101
    #[Override]
102
    public function setStatus(int $status): SpacecraftSystemInterface
103
    {
104
        $this->status = $status;
105
106
        return $this;
107
    }
108
109 7
    #[Override]
110
    public function isHealthy(): bool
111
    {
112 7
        return $this->getStatus() > 0;
113
    }
114
115 2
    #[Override]
116
    public function getName(): string
117
    {
118 2
        return $this->getSystemType()->getDescription();
119
    }
120
121 2
    #[Override]
122
    public function getCssClass(): string
123
    {
124 2
        if ($this->getStatus() < 1) {
125
            return _("sysStatus0");
126 2
        } elseif ($this->getStatus() < 26) {
127
            return _("sysStatus1to25");
128 2
        } elseif ($this->getStatus() < 51) {
129
            return _("sysStatus26to50");
130 2
        } elseif ($this->getStatus() < 76) {
131
            return _("sysStatus51to75");
132
        } else {
133 2
            return _("sysStatus76to100");
134
        }
135
    }
136
137 12
    #[Override]
138
    public function getMode(): SpacecraftSystemModeEnum
139
    {
140 12
        return $this->mode;
141
    }
142
143
    #[Override]
144
    public function setMode(SpacecraftSystemModeEnum $mode): SpacecraftSystemInterface
145
    {
146
        $this->mode = $mode;
147
148
        return $this;
149
    }
150
151 1
    #[Override]
152
    public function getCooldown(): ?int
153
    {
154 1
        return $this->cooldown > time() ? $this->cooldown : null;
155
    }
156
157
    #[Override]
158
    public function setCooldown(int $cooldown): SpacecraftSystemInterface
159
    {
160
        $this->cooldown = $cooldown;
161
162
        return $this;
163
    }
164
165 1
    #[Override]
166
    public function getModule(): ?ModuleInterface
167
    {
168 1
        return $this->module;
169
    }
170
171
    #[Override]
172
    public function setModule(ModuleInterface $module): SpacecraftSystemInterface
173
    {
174
        $this->module = $module;
175
176
        return $this;
177
    }
178
179
    #[Override]
180
    public function getSpacecraft(): SpacecraftInterface
181
    {
182
        return $this->spacecraft;
183
    }
184
185
    #[Override]
186
    public function setSpacecraft(SpacecraftInterface $spacecraft): SpacecraftSystemInterface
187
    {
188
        $this->spacecraft = $spacecraft;
189
        return $this;
190
    }
191
192 12
    #[Override]
193
    public function getData(): ?string
194
    {
195 12
        return $this->data;
196
    }
197
198
    #[Override]
199
    public function setData(string $data): SpacecraftSystemInterface
200
    {
201
        $this->data = $data;
202
        return $this;
203
    }
204
205
    #[Override]
206
    public function determineSystemLevel(): int
207
    {
208
        $module = $this->getModule();
209
210
        if ($module !== null && $module->getLevel() > 0) {
211
            return $module->getLevel();
212
        } else {
213
            return max(1, $this->getSpacecraft()->getRump()->getModuleLevel() - 1);
214
        }
215
    }
216
217
    #[Override]
218
    public function __toString(): string
219
    {
220
        return sprintf(
221
            '"%s": %s',
222
            $this->system_type->name,
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Stu\Component\Spacecraft...pacecraftSystemTypeEnum.
Loading history...
223
            $this->data ?? 'null'
224
        );
225
    }
226
}
227