Passed
Pull Request — master (#2173)
by Janko
25:35 queued 15:23
created

Colony::getDatabaseId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
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\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\OrderBy;
18
use Doctrine\ORM\Mapping\Table;
19
use LogicException;
20
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...
21
use Stu\Component\Colony\ColonyMenuEnum;
22
use Stu\Component\Colony\Trait\ColonyRotationTrait;
23
use Stu\Component\Game\ModuleEnum;
24
use Stu\Lib\Colony\PlanetFieldHostTypeEnum;
25
use Stu\Lib\Transfer\CommodityTransfer;
26
use Stu\Lib\Transfer\TransferEntityTypeEnum;
27
use Stu\Module\Colony\View\ShowColony\ShowColony;
28
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum 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...
29
use Stu\Orm\Repository\ColonyRepository;
30
31
#[Table(name: 'stu_colony')]
32
#[Entity(repositoryClass: ColonyRepository::class)]
33
class Colony implements ColonyInterface
34
{
35
    use ColonyRotationTrait;
36
37
    #[Id]
38
    #[Column(type: 'integer')]
39
    #[GeneratedValue(strategy: 'IDENTITY')]
40
    private int $id;
41
42
    #[OneToOne(targetEntity: ColonyChangeable::class, mappedBy: 'colony', fetch: 'EAGER', cascade: ['all'])]
43
    private ?ColonyChangeableInterface $changeable;
44
45
    #[Column(type: 'integer')]
46
    private int $colonies_classes_id = 0;
0 ignored issues
show
introduced by
The private property $colonies_classes_id is not used, and could be removed.
Loading history...
47
48
    #[Column(type: 'integer')]
49
    private int $user_id = 0;
50
51
    #[Column(type: 'string')]
52
    private string $name = '';
53
54
    #[Column(type: 'string', length: 100)]
55
    private string $planet_name = '';
56
57
    #[Column(type: 'text', nullable: true)]
58
    private ?string $mask = null;
59
60
    #[Column(type: 'integer', nullable: true)]
61
    private ?int $database_id = null;
62
63
    #[Column(type: 'integer', length: 3)]
64
    private int $rotation_factor = 1;
65
66
    #[Column(type: 'integer', length: 2)]
67
    private int $surface_width = 0;
68
69
    #[ManyToOne(targetEntity: ColonyClass::class)]
70
    #[JoinColumn(name: 'colonies_classes_id', nullable: false, referencedColumnName: 'id')]
71
    private ColonyClassInterface $colonyClass;
72
73
    #[OneToOne(targetEntity: StarSystemMap::class, inversedBy: 'colony')]
74
    #[JoinColumn(name: 'starsystem_map_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
75
    private StarSystemMapInterface $starsystem_map;
76
77
    #[ManyToOne(targetEntity: User::class)]
78
    #[JoinColumn(name: 'user_id', nullable: false, referencedColumnName: 'id')]
79
    private UserInterface $user;
80
81
    /**
82
     * @var ArrayCollection<int, PlanetFieldInterface>
83
     */
84
    #[OneToMany(targetEntity: PlanetField::class, mappedBy: 'colony', indexBy: 'field_id', fetch: 'EXTRA_LAZY')]
85
    #[OrderBy(['field_id' => 'ASC'])]
86
    private Collection $planetFields;
87
88
    /**
89
     * @var ArrayCollection<int, StorageInterface>
90
     */
91
    #[OneToMany(targetEntity: Storage::class, mappedBy: 'colony', indexBy: 'commodity_id')]
92
    #[OrderBy(['commodity_id' => 'ASC'])]
93
    private Collection $storage;
94
95
    #[OneToOne(targetEntity: DatabaseEntry::class)]
96
    #[JoinColumn(name: 'database_id', referencedColumnName: 'id')]
97
    private ?DatabaseEntryInterface $databaseEntry;
98
99
    /**
100
     * @var ArrayCollection<int, FleetInterface>
101
     */
102
    #[OneToMany(targetEntity: Fleet::class, mappedBy: 'defendedColony')]
103
    private Collection $defenders;
104
105
    /**
106
     * @var ArrayCollection<int, FleetInterface>
107
     */
108
    #[OneToMany(targetEntity: Fleet::class, mappedBy: 'blockedColony')]
109
    private Collection $blockers;
110
111
    /**
112
     * @var ArrayCollection<int, CrewAssignmentInterface>
113
     */
114
    #[OneToMany(targetEntity: CrewAssignment::class, mappedBy: 'colony')]
115
    private Collection $crewAssignments;
116
117
    /**
118
     * @var ArrayCollection<int, CrewAssignmentInterface>
119
     */
120
    #[OneToMany(targetEntity: CrewTraining::class, mappedBy: 'colony')]
121
    private Collection $crewTrainings;
122
123
    /** @var array<int, int> */
124
    private array $twilightZones = [];
0 ignored issues
show
introduced by
The private property $twilightZones is not used, and could be removed.
Loading history...
125
126
    public function __construct()
127
    {
128
        $this->planetFields = new ArrayCollection();
129
        $this->storage = new ArrayCollection();
130
        $this->defenders = new ArrayCollection();
131
        $this->blockers = new ArrayCollection();
132
        $this->crewAssignments = new ArrayCollection();
133
        $this->crewTrainings = new ArrayCollection();
134
    }
135
136 45
    #[Override]
137
    public function getId(): int
138
    {
139 45
        return $this->id;
140
    }
141
142 23
    #[Override]
143
    public function getChangeable(): ColonyChangeableInterface
144
    {
145 23
        return $this->changeable ?? throw new LogicException('Colony has no changeable');
146
    }
147
148 39
    #[Override]
149
    public function getUserId(): int
150
    {
151 39
        return $this->user_id;
152
    }
153
154 10
    #[Override]
155
    public function getSx(): int
156
    {
157 10
        return $this->getStarsystemMap()->getSx();
158
    }
159
160 10
    #[Override]
161
    public function getSy(): int
162
    {
163 10
        return $this->getStarsystemMap()->getSy();
164
    }
165
166 19
    #[Override]
167
    public function getName(): string
168
    {
169 19
        return $this->name;
170
    }
171
172
    #[Override]
173
    public function setName(string $name): ColonyInterface
174
    {
175
        $this->name = $name;
176
        return $this;
177
    }
178
179 4
    #[Override]
180
    public function getPlanetName(): string
181
    {
182 4
        return $this->planet_name;
183
    }
184
185
    #[Override]
186
    public function setPlanetName(string $planet_name): ColonyInterface
187
    {
188
        $this->planet_name = $planet_name;
189
        return $this;
190
    }
191
192
    #[Override]
193
    public function getMask(): ?string
194
    {
195
        return $this->mask;
196
    }
197
198
    #[Override]
199
    public function setMask(?string $mask): ColonyInterface
200
    {
201
        $this->mask = $mask;
202
        return $this;
203
    }
204
205
    #[Override]
206
    public function getDatabaseId(): ?int
207
    {
208
        return $this->database_id;
209
    }
210
211
    #[Override]
212
    public function setDatabaseEntry(?DatabaseEntryInterface $entry): ColonyInterface
213
    {
214
        $this->databaseEntry = $entry;
215
        return $this;
216
    }
217
218 4
    public function getRotationFactor(): int
219
    {
220 4
        return $this->rotation_factor;
221
    }
222
223
    #[Override]
224
    public function setRotationFactor(int $rotationFactor): ColonyInterface
225
    {
226
        $this->rotation_factor = $rotationFactor;
227
228
        return $this;
229
    }
230
231 6
    #[Override]
232
    public function getSurfaceWidth(): int
233
    {
234 6
        return $this->surface_width;
235
    }
236
237
    #[Override]
238
    public function setSurfaceWidth(int $surfaceWidth): ColonyInterface
239
    {
240
        $this->surface_width = $surfaceWidth;
241
        return $this;
242
    }
243
244 26
    #[Override]
245
    public function getColonyClass(): ColonyClassInterface
246
    {
247 26
        return $this->colonyClass;
248
    }
249
250
    #[Override]
251
    public function setColonyClass(ColonyClassInterface $colonyClass): ColonyInterface
252
    {
253
        $this->colonyClass = $colonyClass;
254
        return $this;
255
    }
256
257 13
    #[Override]
258
    public function getStorageSum(): int
259
    {
260 13
        return array_reduce(
261 13
            $this->getStorage()->getValues(),
262 13
            fn(int $sum, StorageInterface $storage): int => $sum + $storage->getAmount(),
263 13
            0
264 13
        );
265
    }
266
267 19
    #[Override]
268
    public function getStarsystemMap(): StarSystemMapInterface
269
    {
270 19
        return $this->starsystem_map;
271
    }
272
273 10
    #[Override]
274
    public function getLocation(): MapInterface|StarSystemMapInterface
275
    {
276 10
        return $this->getStarsystemMap();
277
    }
278
279
    #[Override]
280
    public function setStarsystemMap(StarSystemMapInterface $systemMap): ColonyInterface
281
    {
282
        $this->starsystem_map = $systemMap;
283
284
        return $this;
285
    }
286
287 10
    #[Override]
288
    public function getSystem(): StarSystemInterface
289
    {
290 10
        return $this->getStarsystemMap()->getSystem();
291
    }
292
293 2
    #[Override]
294
    public function getBeamFactor(): int
295
    {
296 2
        return 10;
297
    }
298
299 5
    #[Override]
300
    public function getPlanetFields(): Collection
301
    {
302 5
        return $this->planetFields;
303
    }
304
305 2
    #[Override]
306
    public function getBeamableStorage(): Collection
307
    {
308 2
        return CommodityTransfer::excludeNonBeamable($this->storage);
309
    }
310
311 20
    #[Override]
312
    public function getStorage(): Collection
313
    {
314 20
        return $this->storage;
315
    }
316
317 1
    #[Override]
318
    public function isDefended(): bool
319
    {
320 1
        return !$this->getDefenders()->isEmpty();
321
    }
322
323 1
    #[Override]
324
    public function getDefenders(): Collection
325
    {
326 1
        return $this->defenders;
327
    }
328
329 1
    #[Override]
330
    public function isBlocked(): bool
331
    {
332 1
        return !$this->getBlockers()->isEmpty();
333
    }
334
335 1
    #[Override]
336
    public function getBlockers(): Collection
337
    {
338 1
        return $this->blockers;
339
    }
340
341
    #[Override]
342
    public function getCrewAssignments(): Collection
343
    {
344
        return $this->crewAssignments;
345
    }
346
347 3
    #[Override]
348
    public function getCrewAssignmentAmount(): int
349
    {
350 3
        return $this->crewAssignments->count();
351
    }
352
353 1
    #[Override]
354
    public function getCrewTrainingAmount(): int
355
    {
356 1
        return $this->crewTrainings->count();
357
    }
358
359 5
    #[Override]
360
    public function isFree(): bool
361
    {
362 5
        return $this->getUserId() === UserEnum::USER_NOONE;
363
    }
364
365 16
    #[Override]
366
    public function getUser(): UserInterface
367
    {
368 16
        return $this->user;
369
    }
370
371
    #[Override]
372
    public function setUser(UserInterface $user): ColonyInterface
373
    {
374
        $this->user = $user;
375
        return $this;
376
    }
377
378 10
    #[Override]
379
    public function getWorkers(): int
380
    {
381 10
        return $this->getChangeable()->getWorkers();
382
    }
383
384 5
    public function getWorkless(): int
385
    {
386 5
        return $this->getChangeable()->getWorkless();
387
    }
388
389 4
    public function getMaxBev(): int
390
    {
391 4
        return $this->getChangeable()->getMaxBev();
392
    }
393
394 9
    #[Override]
395
    public function getMaxEps(): int
396
    {
397 9
        return $this->getChangeable()->getMaxEps();
398
    }
399
400 13
    #[Override]
401
    public function getMaxStorage(): int
402
    {
403 13
        return $this->getChangeable()->getMaxStorage();
404
    }
405
406 10
    #[Override]
407
    public function getPopulation(): int
408
    {
409 10
        return $this->getChangeable()->getPopulation();
410
    }
411
412 2
    #[Override]
413
    public function getSectorString(): string
414
    {
415 2
        return $this->getStarsystemMap()->getSectorString();
416
    }
417
418
    #[Override]
419
    public function isColony(): bool
420
    {
421
        return true;
422
    }
423
424 30
    #[Override]
425
    public function getHostType(): PlanetFieldHostTypeEnum
426
    {
427 30
        return PlanetFieldHostTypeEnum::COLONY;
428
    }
429
430
    #[Override]
431
    public function getDefaultViewIdentifier(): string
432
    {
433
        return ShowColony::VIEW_IDENTIFIER;
434
    }
435
436
    #[Override]
437
    public function isMenuAllowed(ColonyMenuEnum $menu): bool
438
    {
439
        return true;
440
    }
441
442 4
    #[Override]
443
    public function getTransferEntityType(): TransferEntityTypeEnum
444
    {
445 4
        return TransferEntityTypeEnum::COLONY;
446
    }
447
448
    #[Override]
449
    public function getHref(): string
450
    {
451
        return sprintf(
452
            '%s?%s=1&id=%d',
453
            ModuleEnum::COLONY->getPhpPage(),
454
            ShowColony::VIEW_IDENTIFIER,
455
            $this->getId()
456
        );
457
    }
458
459
    #[Override]
460
    public function getComponentParameters(): string
461
    {
462
        return sprintf(
463
            '&hosttype=%d&id=%d',
464
            $this->getHostType()->value,
465
            $this->getId()
466
        );
467
    }
468
}
469