Passed
Push — dev ( da5016...69a1ba )
by Janko
24:07 queued 09:11
created

Colony::getRotationTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\OneToOne;
18
use Doctrine\ORM\Mapping\OrderBy;
19
use Doctrine\ORM\Mapping\Table;
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_colonies')]
32
#[Index(name: 'colony_user_idx', columns: ['user_id'])]
33
#[Index(name: 'colony_classes_idx', columns: ['colonies_classes_id'])]
34
#[Index(name: 'colony_sys_map_idx', columns: ['starsystem_map_id'])]
35
#[Entity(repositoryClass: ColonyRepository::class)]
36
class Colony implements ColonyInterface
37
{
38
    use ColonyRotationTrait;
39
40
    #[Id]
41
    #[Column(type: 'integer')]
42
    #[GeneratedValue(strategy: 'IDENTITY')]
43
    private int $id;
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: 'integer', length: 5)]
58
    private int $bev_work = 0;
59
60
    #[Column(type: 'integer', length: 5)]
61
    private int $bev_free = 0;
62
63
    #[Column(type: 'integer', length: 5)]
64
    private int $bev_max = 0;
65
66
    #[Column(type: 'integer', length: 5)]
67
    private int $eps = 0;
68
69
    #[Column(type: 'integer', length: 5)]
70
    private int $max_eps = 0;
71
72
    #[Column(type: 'integer', length: 5)]
73
    private int $max_storage = 0;
74
75
    #[Column(type: 'text', nullable: true)]
76
    private ?string $mask = null;
77
78
    #[Column(type: 'integer', nullable: true)]
79
    private ?int $database_id = null;
80
81
    #[Column(type: 'integer', length: 5)]
82
    private int $populationlimit = 0;
83
84
    #[Column(type: 'boolean')]
85
    private bool $immigrationstate = true;
86
87
    #[Column(type: 'integer', length: 6, nullable: true)]
88
    private ?int $shields = 0;
89
90
    #[Column(type: 'integer', length: 6, nullable: true)]
91
    private ?int $shield_frequency = 0;
92
93
    #[Column(type: 'integer', length: 3)]
94
    private int $rotation_factor = 1;
95
96
    #[Column(type: 'integer', length: 2)]
97
    private int $surface_width = 0;
98
99
    #[ManyToOne(targetEntity: 'ColonyClass')]
100
    #[JoinColumn(name: 'colonies_classes_id', referencedColumnName: 'id')]
101
    private ColonyClassInterface $colonyClass;
102
103
    #[OneToOne(targetEntity: 'StarSystemMap', inversedBy: 'colony')]
104
    #[JoinColumn(name: 'starsystem_map_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
105
    private StarSystemMapInterface $starsystem_map;
106
107
    #[ManyToOne(targetEntity: 'User')]
108
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id')]
109
    private UserInterface $user;
110
111
    /**
112
     * @var ArrayCollection<int, PlanetFieldInterface>
113
     */
114
    #[OneToMany(targetEntity: 'PlanetField', mappedBy: 'colony', indexBy: 'field_id', fetch: 'EXTRA_LAZY')]
115
    #[OrderBy(['field_id' => 'ASC'])]
116
    private Collection $planetFields;
117
118
    /**
119
     * @var ArrayCollection<int, StorageInterface>
120
     */
121
    #[OneToMany(targetEntity: 'Storage', mappedBy: 'colony', indexBy: 'commodity_id')]
122
    #[OrderBy(['commodity_id' => 'ASC'])]
123
    private Collection $storage;
124
125
    #[ManyToOne(targetEntity: 'TorpedoType')]
126
    #[JoinColumn(name: 'torpedo_type', referencedColumnName: 'id')]
127
    private ?TorpedoTypeInterface $torpedo = null;
128
129
    #[OneToOne(targetEntity: 'DatabaseEntry')]
130
    #[JoinColumn(name: 'database_id', referencedColumnName: 'id')]
131
    private ?DatabaseEntryInterface $databaseEntry;
132
133
    /**
134
     * @var ArrayCollection<int, FleetInterface>
135
     */
136
    #[OneToMany(targetEntity: 'Fleet', mappedBy: 'defendedColony')]
137
    private Collection $defenders;
138
139
    /**
140
     * @var ArrayCollection<int, FleetInterface>
141
     */
142
    #[OneToMany(targetEntity: 'Fleet', mappedBy: 'blockedColony')]
143
    private Collection $blockers;
144
145
    /**
146
     * @var ArrayCollection<int, CrewAssignmentInterface>
147
     */
148
    #[OneToMany(targetEntity: 'CrewAssignment', mappedBy: 'colony')]
149
    private Collection $crewAssignments;
150
151
    /**
152
     * @var ArrayCollection<int, CrewAssignmentInterface>
153
     */
154
    #[OneToMany(targetEntity: 'CrewTraining', mappedBy: 'colony')]
155
    private Collection $crewTrainings;
156
157
    /** @var array<int, int> */
158
    private array $twilightZones = [];
0 ignored issues
show
introduced by
The private property $twilightZones is not used, and could be removed.
Loading history...
159
160
    public function __construct()
161
    {
162
        $this->planetFields = new ArrayCollection();
163
        $this->storage = new ArrayCollection();
164
        $this->defenders = new ArrayCollection();
165
        $this->blockers = new ArrayCollection();
166
        $this->crewAssignments = new ArrayCollection();
167
        $this->crewTrainings = new ArrayCollection();
168
    }
169
170 45
    #[Override]
171
    public function getId(): int
172
    {
173 45
        return $this->id;
174
    }
175
176 39
    #[Override]
177
    public function getUserId(): int
178
    {
179 39
        return $this->user_id;
180
    }
181
182 10
    #[Override]
183
    public function getSx(): int
184
    {
185 10
        return $this->getStarsystemMap()->getSx();
186
    }
187
188 10
    #[Override]
189
    public function getSy(): int
190
    {
191 10
        return $this->getStarsystemMap()->getSy();
192
    }
193
194
    #[Override]
195
    public function getSystemsId(): int
196
    {
197
        return $this->getSystem()->getId();
198
    }
199
200 19
    #[Override]
201
    public function getName(): string
202
    {
203 19
        return $this->name;
204
    }
205
206 2
    #[Override]
207
    public function getNameAndSectorString(): string
208
    {
209 2
        return sprintf(
210 2
            '%s %s',
211 2
            $this->getName(),
212 2
            $this->getSectorString()
213 2
        );
214
    }
215
216 4
    #[Override]
217
    public function getSystemString(): string
218
    {
219 4
        return sprintf('%s-System (%s|%s)', $this->getSystem()->getName(), $this->getSystem()->getCx(), $this->getSystem()->getCy());
220
    }
221
222
    #[Override]
223
    public function setName(string $name): ColonyInterface
224
    {
225
        $this->name = $name;
226
        return $this;
227
    }
228
229 4
    #[Override]
230
    public function getPlanetName(): string
231
    {
232 4
        return $this->planet_name;
233
    }
234
235
    #[Override]
236
    public function setPlanetName(string $planet_name): ColonyInterface
237
    {
238
        $this->planet_name = $planet_name;
239
        return $this;
240
    }
241
242 10
    #[Override]
243
    public function getWorkers(): int
244
    {
245 10
        return $this->bev_work;
246
    }
247
248
    #[Override]
249
    public function setWorkers(int $bev_work): ColonyInterface
250
    {
251
        $this->bev_work = $bev_work;
252
        return $this;
253
    }
254
255 10
    #[Override]
256
    public function getWorkless(): int
257
    {
258 10
        return $this->bev_free;
259
    }
260
261
    #[Override]
262
    public function setWorkless(int $bev_free): ColonyInterface
263
    {
264
        $this->bev_free = $bev_free;
265
        return $this;
266
    }
267
268 5
    #[Override]
269
    public function getMaxBev(): int
270
    {
271 5
        return $this->bev_max;
272
    }
273
274
    #[Override]
275
    public function setMaxBev(int $bev_max): ColonyInterface
276
    {
277
        $this->bev_max = $bev_max;
278
        return $this;
279
    }
280
281 11
    #[Override]
282
    public function getEps(): int
283
    {
284 11
        return $this->eps;
285
    }
286
287
    #[Override]
288
    public function setEps(int $eps): ColonyInterface
289
    {
290
        $this->eps = $eps;
291
        return $this;
292
    }
293
294 9
    #[Override]
295
    public function getMaxEps(): int
296
    {
297 9
        return $this->max_eps;
298
    }
299
300
    #[Override]
301
    public function setMaxEps(int $max_eps): ColonyInterface
302
    {
303
        $this->max_eps = $max_eps;
304
        return $this;
305
    }
306
307 13
    #[Override]
308
    public function getMaxStorage(): int
309
    {
310 13
        return $this->max_storage;
311
    }
312
313
    #[Override]
314
    public function setMaxStorage(int $max_storage): ColonyInterface
315
    {
316
        $this->max_storage = $max_storage;
317
        return $this;
318
    }
319
320
    #[Override]
321
    public function getMask(): ?string
322
    {
323
        return $this->mask;
324
    }
325
326
    #[Override]
327
    public function setMask(?string $mask): ColonyInterface
328
    {
329
        $this->mask = $mask;
330
        return $this;
331
    }
332
333
    #[Override]
334
    public function getDatabaseId(): ?int
335
    {
336
        return $this->database_id;
337
    }
338
339
    #[Override]
340
    public function setDatabaseEntry(?DatabaseEntryInterface $entry): ColonyInterface
341
    {
342
        $this->databaseEntry = $entry;
343
        return $this;
344
    }
345
346 6
    #[Override]
347
    public function getPopulationlimit(): int
348
    {
349 6
        return $this->populationlimit;
350
    }
351
352
    #[Override]
353
    public function setPopulationlimit(int $populationlimit): ColonyInterface
354
    {
355
        $this->populationlimit = $populationlimit;
356
        return $this;
357
    }
358
359 6
    #[Override]
360
    public function getImmigrationstate(): bool
361
    {
362 6
        return $this->immigrationstate;
363
    }
364
365
    #[Override]
366
    public function setImmigrationstate(bool $immigrationstate): ColonyInterface
367
    {
368
        $this->immigrationstate = $immigrationstate;
369
        return $this;
370
    }
371
372
    #[Override]
373
    public function getShields(): ?int
374
    {
375
        return $this->shields;
376
    }
377
378
    #[Override]
379
    public function setShields(?int $shields): ColonyInterface
380
    {
381
        $this->shields = $shields;
382
        return $this;
383
    }
384
385
    #[Override]
386
    public function getShieldFrequency(): ?int
387
    {
388
        return $this->shield_frequency;
389
    }
390
391
    #[Override]
392
    public function setShieldFrequency(?int $shieldFrequency): ColonyInterface
393
    {
394
        $this->shield_frequency = $shieldFrequency;
395
        return $this;
396
    }
397
398
    #[Override]
399
    public function getTorpedo(): ?TorpedoTypeInterface
400
    {
401
        return $this->torpedo;
402
    }
403
404
    #[Override]
405
    public function setTorpedo(?TorpedoTypeInterface $torpedoType): ColonyInterface
406
    {
407
        $this->torpedo = $torpedoType;
408
        return $this;
409
    }
410
411 4
    #[Override]
412
    public function getRotationFactor(): int
413
    {
414 4
        return $this->rotation_factor;
415
    }
416
417
    #[Override]
418
    public function setRotationFactor(int $rotationFactor): ColonyInterface
419
    {
420
        $this->rotation_factor = $rotationFactor;
421
422
        return $this;
423
    }
424
425 6
    #[Override]
426
    public function getSurfaceWidth(): int
427
    {
428 6
        return $this->surface_width;
429
    }
430
431
    #[Override]
432
    public function setSurfaceWidth(int $surfaceWidth): ColonyInterface
433
    {
434
        $this->surface_width = $surfaceWidth;
435
        return $this;
436
    }
437
438 26
    #[Override]
439
    public function getColonyClass(): ColonyClassInterface
440
    {
441 26
        return $this->colonyClass;
442
    }
443
444
    #[Override]
445
    public function setColonyClass(ColonyClassInterface $colonyClass): ColonyInterface
446
    {
447
        $this->colonyClass = $colonyClass;
448
        return $this;
449
    }
450
451 13
    #[Override]
452
    public function getStorageSum(): int
453
    {
454 13
        return array_reduce(
455 13
            $this->getStorage()->getValues(),
456 13
            fn(int $sum, StorageInterface $storage): int => $sum + $storage->getAmount(),
457 13
            0
458 13
        );
459
    }
460
461
    #[Override]
462
    public function storagePlaceLeft(): bool
463
    {
464
        return $this->getMaxStorage() > $this->getStorageSum();
465
    }
466
467 19
    #[Override]
468
    public function getStarsystemMap(): StarSystemMapInterface
469
    {
470 19
        return $this->starsystem_map;
471
    }
472
473 10
    #[Override]
474
    public function getLocation(): MapInterface|StarSystemMapInterface
475
    {
476 10
        return $this->getStarsystemMap();
477
    }
478
479
    #[Override]
480
    public function setStarsystemMap(StarSystemMapInterface $systemMap): ColonyInterface
481
    {
482
        $this->starsystem_map = $systemMap;
483
484
        return $this;
485
    }
486
487 10
    #[Override]
488
    public function getSystem(): StarSystemInterface
489
    {
490 10
        return $this->getStarsystemMap()->getSystem();
491
    }
492
493 2
    #[Override]
494
    public function getBeamFactor(): int
495
    {
496 2
        return 10;
497
    }
498
499 5
    #[Override]
500
    public function getPlanetFields(): Collection
501
    {
502 5
        return $this->planetFields;
503
    }
504
505 2
    #[Override]
506
    public function getBeamableStorage(): Collection
507
    {
508 2
        return CommodityTransfer::excludeNonBeamable($this->storage);
509
    }
510
511 20
    #[Override]
512
    public function getStorage(): Collection
513
    {
514 20
        return $this->storage;
515
    }
516
517 1
    #[Override]
518
    public function isDefended(): bool
519
    {
520 1
        return !$this->getDefenders()->isEmpty();
521
    }
522
523 1
    #[Override]
524
    public function getDefenders(): Collection
525
    {
526 1
        return $this->defenders;
527
    }
528
529 1
    #[Override]
530
    public function isBlocked(): bool
531
    {
532 1
        return !$this->getBlockers()->isEmpty();
533
    }
534
535 1
    #[Override]
536
    public function getBlockers(): Collection
537
    {
538 1
        return $this->blockers;
539
    }
540
541
    #[Override]
542
    public function getCrewAssignments(): Collection
543
    {
544
        return $this->crewAssignments;
545
    }
546
547 3
    #[Override]
548
    public function getCrewAssignmentAmount(): int
549
    {
550 3
        return $this->crewAssignments->count();
551
    }
552
553 1
    #[Override]
554
    public function getCrewTrainingAmount(): int
555
    {
556 1
        return $this->crewTrainings->count();
557
    }
558
559 5
    #[Override]
560
    public function isFree(): bool
561
    {
562 5
        return $this->getUserId() === UserEnum::USER_NOONE;
563
    }
564
565 16
    #[Override]
566
    public function getUser(): UserInterface
567
    {
568 16
        return $this->user;
569
    }
570
571
    #[Override]
572
    public function setUser(UserInterface $user): ColonyInterface
573
    {
574
        $this->user = $user;
575
        return $this;
576
    }
577
578 10
    #[Override]
579
    public function getPopulation(): int
580
    {
581 10
        return $this->getWorkers() + $this->getWorkless();
582
    }
583
584 4
    #[Override]
585
    public function getFreeHousing(): int
586
    {
587 4
        return $this->getMaxBev() - $this->getPopulation();
588
    }
589
590
    #[Override]
591
    public function lowerEps(int $value): void
592
    {
593
        $this->setEps($this->getEps() - $value);
594
    }
595
596
    #[Override]
597
    public function upperEps(int $value): void
598
    {
599
        $this->setEps($this->getEps() + $value);
600
    }
601
602 2
    #[Override]
603
    public function getSectorString(): string
604
    {
605 2
        return $this->getStarsystemMap()->getSectorString();
606
    }
607
608 12
    #[Override]
609
    public function getPlanetFieldHostIdentifier(): string
610
    {
611 12
        return 'colony';
612
    }
613
614 15
    #[Override]
615
    public function getPlanetFieldHostColumnIdentifier(): string
616
    {
617 15
        return 'colonies_id';
618
    }
619
620
    #[Override]
621
    public function isColony(): bool
622
    {
623
        return true;
624
    }
625
626 20
    #[Override]
627
    public function getHostType(): PlanetFieldHostTypeEnum
628
    {
629 20
        return PlanetFieldHostTypeEnum::COLONY;
630
    }
631
632
    #[Override]
633
    public function getDefaultViewIdentifier(): string
634
    {
635
        return ShowColony::VIEW_IDENTIFIER;
636
    }
637
638
    #[Override]
639
    public function isMenuAllowed(ColonyMenuEnum $menu): bool
640
    {
641
        return true;
642
    }
643
644 4
    #[Override]
645
    public function getTransferEntityType(): TransferEntityTypeEnum
646
    {
647 4
        return TransferEntityTypeEnum::COLONY;
648
    }
649
650
    #[Override]
651
    public function getHref(): string
652
    {
653
        return sprintf(
654
            '%s?%s=1&id=%d',
655
            ModuleEnum::COLONY->getPhpPage(),
656
            ShowColony::VIEW_IDENTIFIER,
657
            $this->getId()
658
        );
659
    }
660
661
    #[Override]
662
    public function getComponentParameters(): string
663
    {
664
        return sprintf(
665
            '&hosttype=%d&id=%d',
666
            $this->getHostType()->value,
667
            $this->getId()
668
        );
669
    }
670
}
671