Passed
Push — dev ( 25004f...be11ce )
by Janko
16:12
created

Colony::setMaxEps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0

1 Method

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