Passed
Push — master ( 5a11dc...578008 )
by Janko
08:39
created

SpacecraftRump::getBeamFactor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\JoinColumn;
14
use Doctrine\ORM\Mapping\ManyToOne;
15
use Doctrine\ORM\Mapping\OneToMany;
16
use Doctrine\ORM\Mapping\OneToOne;
17
use Doctrine\ORM\Mapping\Table;
18
use LogicException;
19
use Stu\Component\Spacecraft\SpacecraftRumpCategoryEnum;
20
use Stu\Component\Spacecraft\SpacecraftRumpRoleEnum;
21
use Stu\Orm\Repository\SpacecraftRumpRepository;
22
23
#[Table(name: 'stu_rump')]
24
#[Entity(repositoryClass: SpacecraftRumpRepository::class)]
25
class SpacecraftRump
26
{
27
    // spacecraft can colonize
28
    public const int SPECIAL_ABILITY_COLONIZE = 1;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 28 at column 21
Loading history...
29
30
    #[Id]
31
    #[Column(type: 'integer')]
32
    #[GeneratedValue(strategy: 'IDENTITY')]
33
    private int $id;
34
35
    #[OneToOne(targetEntity: SpacecraftRumpBaseValues::class, mappedBy: 'rump', fetch: 'EXTRA_LAZY', cascade: ['all'])]
36
    private ?SpacecraftRumpBaseValues $baseValues;
37
38
    #[column(type: 'integer', enumType: SpacecraftRumpCategoryEnum::class, nullable: false)]
39
    private SpacecraftRumpCategoryEnum $category_id;
40
41
    #[column(type: 'integer', enumType: SpacecraftRumpRoleEnum::class, nullable: true)]
42
    private ?SpacecraftRumpRoleEnum $role_id = null;
43
44
    #[column(type: 'smallint')]
45
    private int $phaser_volleys = 0;
46
47
    #[column(type: 'smallint')]
48
    private int $phaser_hull_damage_factor = 0;
49
50
    #[column(type: 'smallint')]
51
    private int $phaser_shield_damage_factor = 0;
52
53
    #[column(type: 'smallint')]
54
    private int $torpedo_level = 0;
55
56
    #[column(type: 'smallint')]
57
    private int $torpedo_volleys = 0;
58
59
    #[column(type: 'smallint')]
60
    private int $base_torpedo_storage = 0;
61
62
    #[Column(type: 'string')]
63
    private string $name = '';
64
65
    #[Column(type: 'boolean')]
66
    private bool $is_buildable;
67
68
    #[Column(type: 'boolean')]
69
    private bool $is_npc;
70
71
    #[column(type: 'smallint')]
72
    private int $eps_cost = 0;
73
74
    #[column(type: 'integer')]
75
    private int $storage = 0;
76
77
    #[column(type: 'smallint')]
78
    private int $slots = 0;
79
80
    #[column(type: 'integer')]
81
    private int $buildtime = 0;
82
83
    #[column(type: 'smallint', nullable: true)]
84
    private ?int $needed_workbees = null;
85
86
    #[column(type: 'smallint')]
87
    private int $sort = 0;
88
89
    #[column(type: 'integer', nullable: true)]
90
    private ?int $database_id = 0;
91
92
    #[column(type: 'integer', nullable: true)]
93
    private ?int $commodity_id = 0;
94
95
    #[column(type: 'smallint')]
96
    private int $flight_ecost = 0;
97
98
    #[column(type: 'smallint')]
99
    private int $beam_factor = 0;
100
101
    #[column(type: 'smallint')]
102
    private int $shuttle_slots = 0;
103
104
    #[column(type: 'integer')]
105
    private int $tractor_mass = 1;
106
107
    #[column(type: 'integer')]
108
    private int $tractor_payload = 100;
109
110
    #[Column(type: 'integer')]
111
    private int $prestige;
112
113
    #[Column(type: 'boolean', nullable: true)]
114
    private ?bool $npc_buildable = true;
115
116
    #[ManyToOne(targetEntity: ShipRumpRole::class)]
117
    #[JoinColumn(name: 'role_id', referencedColumnName: 'id')]
118
    private ?ShipRumpRole $shipRumpRole = null;
119
120
    /**
121
     * @var ArrayCollection<int, ShipRumpSpecial>
122
     */
123
    #[OneToMany(targetEntity: ShipRumpSpecial::class, mappedBy: 'spacecraftRump', indexBy: 'special')]
124
    private Collection $specialAbilities;
125
126
    #[ManyToOne(targetEntity: ShipRumpCategory::class)]
127
    #[JoinColumn(name: 'category_id', nullable: false, referencedColumnName: 'id')]
128
    private ShipRumpCategory $shipRumpCategory;
129
130
    #[ManyToOne(targetEntity: Commodity::class)]
131
    #[JoinColumn(name: 'commodity_id', referencedColumnName: 'id')]
132
    private ?Commodity $commodity = null;
133
134
    #[ManyToOne(targetEntity: DatabaseEntry::class)]
135
    #[JoinColumn(name: 'database_id', referencedColumnName: 'id')]
136
    private ?DatabaseEntry $databaseEntry = null;
137
138
    /**
139
     * @var ArrayCollection<int, ShipRumpCost>
140
     */
141
    #[OneToMany(targetEntity: ShipRumpCost::class, mappedBy: 'spacecraftRump')]
142
    private Collection $buildingCosts;
143
144
    /**
145
     * @var ArrayCollection<int, BuildplanHangar>
146
     */
147
    #[OneToMany(targetEntity: BuildplanHangar::class, mappedBy: 'spacecraftRump')]
148
    private Collection $startHangar;
149
150
    public function __construct()
151
    {
152
        $this->buildingCosts = new ArrayCollection();
153
        $this->startHangar = new ArrayCollection();
154
        $this->specialAbilities = new ArrayCollection();
155
    }
156
157 39
    public function getId(): int
158
    {
159 39
        return $this->id;
160
    }
161
162 12
    public function getBaseValues(): SpacecraftRumpBaseValues
163
    {
164 12
        return $this->baseValues ?? throw new LogicException('Rump has no base balues');
165
    }
166
167 17
    public function getCategoryId(): SpacecraftRumpCategoryEnum
168
    {
169 17
        return $this->category_id;
170
    }
171
172 19
    public function getRoleId(): ?SpacecraftRumpRoleEnum
173
    {
174 19
        return $this->role_id;
175
    }
176
177 17
    public function getBeamFactor(): int
178
    {
179 17
        return $this->beam_factor;
180
    }
181
182 2
    public function getShuttleSlots(): int
183
    {
184 2
        return $this->shuttle_slots;
185
    }
186
187 2
    public function getTractorMass(): int
188
    {
189 2
        return $this->tractor_mass;
190
    }
191
192 2
    public function getTractorPayload(): int
193
    {
194 2
        return $this->tractor_payload;
195
    }
196
197 6
    public function getPhaserVolleys(): int
198
    {
199 6
        return $this->phaser_volleys;
200
    }
201
202
    public function getPhaserHullDamageFactor(): int
203
    {
204
        return $this->phaser_hull_damage_factor;
205
    }
206
207
    public function getPhaserShieldDamageFactor(): int
208
    {
209
        return $this->phaser_shield_damage_factor;
210
    }
211
212 6
    public function getTorpedoLevel(): int
213
    {
214 6
        return $this->torpedo_level;
215
    }
216
217 6
    public function getTorpedoVolleys(): int
218
    {
219 6
        return $this->torpedo_volleys;
220
    }
221
222 8
    public function getBaseTorpedoStorage(): int
223
    {
224 8
        return $this->base_torpedo_storage;
225
    }
226
227 26
    public function getName(): string
228
    {
229 26
        return $this->name;
230
    }
231
232
    public function setName(string $name): SpacecraftRump
233
    {
234
        $this->name = $name;
235
        return $this;
236
    }
237
238
    public function getIsBuildable(): bool
239
    {
240
        return $this->is_buildable;
241
    }
242
243
    public function setIsBuildable(bool $isBuildable): SpacecraftRump
244
    {
245
        $this->is_buildable = $isBuildable;
246
        return $this;
247
    }
248
249 1
    public function getIsNpc(): bool
250
    {
251 1
        return $this->is_npc;
252
    }
253
254
    public function setIsNpc(bool $isNpc): SpacecraftRump
255
    {
256
        $this->is_npc = $isNpc;
257
        return $this;
258
    }
259
260 4
    public function getEpsCost(): int
261
    {
262 4
        return $this->eps_cost;
263
    }
264
265
    public function setEpsCost(int $energyCosts): SpacecraftRump
266
    {
267
        $this->eps_cost = $energyCosts;
268
        return $this;
269
    }
270
271 19
    public function getStorage(): int
272
    {
273 19
        return $this->storage;
274
    }
275
276
    public function setStorage(int $storage): SpacecraftRump
277
    {
278
        $this->storage = $storage;
279
        return $this;
280
    }
281
282 2
    public function getDockingSlots(): int
283
    {
284 2
        return $this->slots;
285
    }
286
287
    public function setDockingSlots(int $slots): SpacecraftRump
288
    {
289
        $this->slots = $slots;
290
        return $this;
291
    }
292
293 4
    public function getBuildtime(): int
294
    {
295 4
        return $this->buildtime;
296
    }
297
298
    public function setBuildtime(int $buildtime): SpacecraftRump
299
    {
300
        $this->buildtime = $buildtime;
301
        return $this;
302
    }
303
304
    public function getSort(): int
305
    {
306
        return $this->sort;
307
    }
308
309
    public function setSort(int $sort): SpacecraftRump
310
    {
311
        $this->sort = $sort;
312
        return $this;
313
    }
314
315
    public function getDatabaseId(): ?int
316
    {
317
        return $this->database_id;
318
    }
319
320
    public function getCommodityId(): ?int
321
    {
322
        return $this->commodity_id;
323
    }
324
325
    public function setCommodityId(?int $commodityId): SpacecraftRump
326
    {
327
        $this->commodity_id = $commodityId;
328
        return $this;
329
    }
330
331 8
    public function getFlightEcost(): int
332
    {
333 8
        return $this->flight_ecost;
334
    }
335
336 5
    public function getShipRumpRole(): ?ShipRumpRole
337
    {
338 5
        return $this->shipRumpRole;
339
    }
340
341 4
    public function getShipRumpCategory(): ShipRumpCategory
342
    {
343 4
        return $this->shipRumpCategory;
344
    }
345
346
    public function getCommodity(): ?Commodity
347
    {
348
        return $this->commodity;
349
    }
350
351
    public function setCommodity(?Commodity $commodity): SpacecraftRump
352
    {
353
        $this->commodity = $commodity;
354
        return $this;
355
    }
356
357
    public function getNeededWorkbees(): ?int
358
    {
359
        return $this->needed_workbees;
360
    }
361
362
    public function getNeededRepairWorkbees(): ?int
363
    {
364
        return  $this->getNeededWorkbees() / 5;
365
    }
366
367
    public function getDatabaseEntry(): ?DatabaseEntry
368
    {
369
        return $this->databaseEntry;
370
    }
371
372
    public function setDatabaseEntry(?DatabaseEntry $databaseEntry): SpacecraftRump
373
    {
374
        $this->databaseEntry = $databaseEntry;
375
        return $this;
376
    }
377
378
    public function getPrestige(): int
379
    {
380
        return $this->prestige;
381
    }
382
383
    public function isEscapePods(): bool
384
    {
385
        return $this->getCategoryId() === SpacecraftRumpCategoryEnum::SHIP_CATEGORY_ESCAPE_PODS;
386
    }
387
388 1
    public function isShipyard(): bool
389
    {
390 1
        return $this->getCategoryId() === SpacecraftRumpCategoryEnum::SHIP_CATEGORY_STATION
391 1
            && $this->getRoleId() === SpacecraftRumpRoleEnum::SHIPYARD;
392
    }
393
394 1
    public function isStation(): bool
395
    {
396 1
        return $this->getCategoryId() === SpacecraftRumpCategoryEnum::SHIP_CATEGORY_STATION;
397
    }
398
399
    public function isWorkbee(): bool
400
    {
401
        $commodity = $this->getCommodity();
402
403
        return $commodity !== null && $commodity->isWorkbee();
404
    }
405
406
    /**
407
     * @return Collection<int, BuildplanHangar>
408
     */
409
    public function getStartHangar(): Collection
410
    {
411
        return $this->startHangar;
412
    }
413
414
    /**
415
     * @return Collection<int, ShipRumpCost>
416
     */
417 4
    public function getBuildingCosts(): Collection
418
    {
419 4
        return $this->buildingCosts;
420
    }
421
422
    public function hasSpecialAbility(int $value): bool
423
    {
424
        return $this->specialAbilities->containsKey($value);
425
    }
426
427 1
    public function getFactionId(): int
428
    {
429
        //last digit of id shows faction id
430 1
        return $this->getId() % 10;
431
    }
432
433
    /**
434
     * @return Collection<int, ShipRumpSpecial>
435
     */
436
    public function getSpecialAbilities(): Collection
437
    {
438
        return $this->specialAbilities;
439
    }
440
441
    public function getNpcBuildable(): ?bool
442
    {
443
        return $this->npc_buildable;
444
    }
445
446
    public function setNpcBuildable(?bool $npcBuildable): SpacecraftRump
447
    {
448
        $this->npc_buildable = $npcBuildable;
449
        return $this;
450
    }
451
}
452