Passed
Push — dev ( 563b2a...8aea1d )
by Janko
15:01
created

Colony::getUserId()   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\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 19
    #[Override]
166
    public function getName(): string
167
    {
168 19
        return $this->name;
169
    }
170
171
    #[Override]
172
    public function setName(string $name): ColonyInterface
173
    {
174
        $this->name = $name;
175
        return $this;
176
    }
177
178 4
    #[Override]
179
    public function getPlanetName(): string
180
    {
181 4
        return $this->planet_name;
182
    }
183
184
    #[Override]
185
    public function setPlanetName(string $planet_name): ColonyInterface
186
    {
187
        $this->planet_name = $planet_name;
188
        return $this;
189
    }
190
191
    #[Override]
192
    public function getMask(): ?string
193
    {
194
        return $this->mask;
195
    }
196
197
    #[Override]
198
    public function setMask(?string $mask): ColonyInterface
199
    {
200
        $this->mask = $mask;
201
        return $this;
202
    }
203
204
    #[Override]
205
    public function getDatabaseId(): ?int
206
    {
207
        return $this->database_id;
208
    }
209
210
    #[Override]
211
    public function setDatabaseEntry(?DatabaseEntryInterface $entry): ColonyInterface
212
    {
213
        $this->databaseEntry = $entry;
214
        return $this;
215
    }
216
217 4
    public function getRotationFactor(): int
218
    {
219 4
        return $this->rotation_factor;
220
    }
221
222
    #[Override]
223
    public function setRotationFactor(int $rotationFactor): ColonyInterface
224
    {
225
        $this->rotation_factor = $rotationFactor;
226
227
        return $this;
228
    }
229
230 6
    #[Override]
231
    public function getSurfaceWidth(): int
232
    {
233 6
        return $this->surface_width;
234
    }
235
236
    #[Override]
237
    public function setSurfaceWidth(int $surfaceWidth): ColonyInterface
238
    {
239
        $this->surface_width = $surfaceWidth;
240
        return $this;
241
    }
242
243 26
    #[Override]
244
    public function getColonyClass(): ColonyClassInterface
245
    {
246 26
        return $this->colonyClass;
247
    }
248
249
    #[Override]
250
    public function setColonyClass(ColonyClassInterface $colonyClass): ColonyInterface
251
    {
252
        $this->colonyClass = $colonyClass;
253
        return $this;
254
    }
255
256 13
    #[Override]
257
    public function getStorageSum(): int
258
    {
259 13
        return array_reduce(
260 13
            $this->getStorage()->getValues(),
261 13
            fn(int $sum, StorageInterface $storage): int => $sum + $storage->getAmount(),
262 13
            0
263 13
        );
264
    }
265
266 19
    #[Override]
267
    public function getStarsystemMap(): StarSystemMapInterface
268
    {
269 19
        return $this->starsystem_map;
270
    }
271
272 10
    #[Override]
273
    public function getLocation(): MapInterface|StarSystemMapInterface
274
    {
275 10
        return $this->getStarsystemMap();
276
    }
277
278
    #[Override]
279
    public function setStarsystemMap(StarSystemMapInterface $systemMap): ColonyInterface
280
    {
281
        $this->starsystem_map = $systemMap;
282
283
        return $this;
284
    }
285
286 10
    #[Override]
287
    public function getSystem(): StarSystemInterface
288
    {
289 10
        return $this->getStarsystemMap()->getSystem();
290
    }
291
292 2
    #[Override]
293
    public function getBeamFactor(): int
294
    {
295 2
        return 10;
296
    }
297
298 5
    #[Override]
299
    public function getPlanetFields(): Collection
300
    {
301 5
        return $this->planetFields;
302
    }
303
304 2
    #[Override]
305
    public function getBeamableStorage(): Collection
306
    {
307 2
        return CommodityTransfer::excludeNonBeamable($this->storage);
308
    }
309
310 20
    #[Override]
311
    public function getStorage(): Collection
312
    {
313 20
        return $this->storage;
314
    }
315
316 1
    #[Override]
317
    public function isDefended(): bool
318
    {
319 1
        return !$this->getDefenders()->isEmpty();
320
    }
321
322 1
    #[Override]
323
    public function getDefenders(): Collection
324
    {
325 1
        return $this->defenders;
326
    }
327
328 1
    #[Override]
329
    public function isBlocked(): bool
330
    {
331 1
        return !$this->getBlockers()->isEmpty();
332
    }
333
334 1
    #[Override]
335
    public function getBlockers(): Collection
336
    {
337 1
        return $this->blockers;
338
    }
339
340
    #[Override]
341
    public function getCrewAssignments(): Collection
342
    {
343
        return $this->crewAssignments;
344
    }
345
346 3
    #[Override]
347
    public function getCrewAssignmentAmount(): int
348
    {
349 3
        return $this->crewAssignments->count();
350
    }
351
352 1
    #[Override]
353
    public function getCrewTrainingAmount(): int
354
    {
355 1
        return $this->crewTrainings->count();
356
    }
357
358 5
    #[Override]
359
    public function isFree(): bool
360
    {
361 5
        return $this->getUserId() === UserEnum::USER_NOONE;
362
    }
363
364 16
    #[Override]
365
    public function getUser(): UserInterface
366
    {
367 16
        return $this->user;
368
    }
369
370
    #[Override]
371
    public function setUser(UserInterface $user): ColonyInterface
372
    {
373
        $this->user = $user;
374
        return $this;
375
    }
376
377 10
    #[Override]
378
    public function getWorkers(): int
379
    {
380 10
        return $this->changeable->getWorkers();
381
    }
382
383 5
    public function getWorkless(): int
384
    {
385 5
        return $this->changeable->getWorkless();
386
    }
387
388 4
    public function getMaxBev(): int
389
    {
390 4
        return $this->changeable->getMaxBev();
391
    }
392
393 9
    #[Override]
394
    public function getMaxEps(): int
395
    {
396 9
        return $this->changeable->getMaxEps();
397
    }
398
399 13
    #[Override]
400
    public function getMaxStorage(): int
401
    {
402 13
        return $this->changeable->getMaxStorage();
403
    }
404
405 10
    #[Override]
406
    public function getPopulation(): int
407
    {
408 10
        return $this->changeable->getPopulation();
409
    }
410
411 2
    #[Override]
412
    public function getSectorString(): string
413
    {
414 2
        return $this->getStarsystemMap()->getSectorString();
415
    }
416
417
    #[Override]
418
    public function isColony(): bool
419
    {
420
        return true;
421
    }
422
423 30
    #[Override]
424
    public function getHostType(): PlanetFieldHostTypeEnum
425
    {
426 30
        return PlanetFieldHostTypeEnum::COLONY;
427
    }
428
429
    #[Override]
430
    public function getDefaultViewIdentifier(): string
431
    {
432
        return ShowColony::VIEW_IDENTIFIER;
433
    }
434
435
    #[Override]
436
    public function isMenuAllowed(ColonyMenuEnum $menu): bool
437
    {
438
        return true;
439
    }
440
441 4
    #[Override]
442
    public function getTransferEntityType(): TransferEntityTypeEnum
443
    {
444 4
        return TransferEntityTypeEnum::COLONY;
445
    }
446
447
    #[Override]
448
    public function getHref(): string
449
    {
450
        return sprintf(
451
            '%s?%s=1&id=%d',
452
            ModuleEnum::COLONY->getPhpPage(),
453
            ShowColony::VIEW_IDENTIFIER,
454
            $this->getId()
455
        );
456
    }
457
458
    #[Override]
459
    public function getComponentParameters(): string
460
    {
461
        return sprintf(
462
            '&hosttype=%d&id=%d',
463
            $this->getHostType()->value,
464
            $this->getId()
465
        );
466
    }
467
}
468