Passed
Push — dev ( 117aec...fd7324 )
by Janko
15:18
created

Spacecraft::setLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
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\DiscriminatorColumn;
11
use Doctrine\ORM\Mapping\DiscriminatorMap;
12
use Doctrine\ORM\Mapping\Entity;
13
use Doctrine\ORM\Mapping\GeneratedValue;
14
use Doctrine\ORM\Mapping\Id;
15
use Doctrine\ORM\Mapping\InheritanceType;
16
use Doctrine\ORM\Mapping\JoinColumn;
17
use Doctrine\ORM\Mapping\ManyToOne;
18
use Doctrine\ORM\Mapping\OneToMany;
19
use Doctrine\ORM\Mapping\OneToOne;
20
use Doctrine\ORM\Mapping\OrderBy;
21
use Doctrine\ORM\Mapping\Table;
22
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...
23
use RuntimeException;
24
use Stu\Component\Spacecraft\SpacecraftModuleTypeEnum;
25
use Stu\Component\Spacecraft\SpacecraftStateEnum;
26
use Stu\Component\Spacecraft\SpacecraftTypeEnum;
27
use Stu\Component\Spacecraft\Trait\SpacecraftSystemExistenceTrait;
28
use Stu\Component\Spacecraft\Trait\SpacecrafCharacteristicsTrait;
29
use Stu\Component\Spacecraft\Trait\SpacecraftCrewTrait;
30
use Stu\Component\Spacecraft\Trait\SpacecraftHoldingWebTrait;
31
use Stu\Component\Spacecraft\Trait\SpacecraftHrefTrait;
32
use Stu\Component\Spacecraft\Trait\SpacecraftHullColorStyleTrait;
33
use Stu\Component\Spacecraft\Trait\SpacecraftInteractionTrait;
34
use Stu\Component\Spacecraft\Trait\SpacecraftLocationTrait;
35
use Stu\Component\Spacecraft\Trait\SpacecraftShieldsTrait;
36
use Stu\Component\Spacecraft\Trait\SpacecraftStateTrait;
37
use Stu\Component\Spacecraft\Trait\SpacecraftStorageTrait;
38
use Stu\Component\Spacecraft\Trait\SpacecraftSystemHealthTrait;
39
use Stu\Component\Spacecraft\Trait\SpacecraftSystemStateTrait;
40
use Stu\Component\Spacecraft\Trait\SpacecraftTorpedoTrait;
41
use Stu\Orm\Repository\SpacecraftRepository;
42
43
#[Table(name: 'stu_spacecraft')]
44
#[Entity(repositoryClass: SpacecraftRepository::class)]
45
#[InheritanceType('JOINED')]
46
#[DiscriminatorColumn(name: 'type', type: 'string')]
47
#[DiscriminatorMap([
48
    SpacecraftTypeEnum::SHIP->value => Ship::class,
49
    SpacecraftTypeEnum::STATION->value => Station::class,
50
    SpacecraftTypeEnum::THOLIAN_WEB->value => TholianWeb::class
51
])]
52
abstract class Spacecraft implements SpacecraftInterface
53
{
54
    use SpacecraftSystemStateTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...cecraftSystemStateTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
55
    use SpacecraftSystemExistenceTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...aftSystemExistenceTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
56
    use SpacecraftSystemHealthTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...ecraftSystemHealthTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
57
    use SpacecraftShieldsTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...\SpacecraftShieldsTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
58
    use SpacecraftCrewTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft\Trait\SpacecraftCrewTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
59
    use SpacecraftLocationTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...SpacecraftLocationTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
60
    use SpacecraftStorageTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...\SpacecraftStorageTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
61
    use SpacecraftInteractionTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...cecraftInteractionTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
62
    use SpacecraftHoldingWebTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...acecraftHoldingWebTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
63
    use SpacecraftHullColorStyleTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...raftHullColorStyleTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
64
    use SpacecraftTorpedoTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...\SpacecraftTorpedoTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
65
    use SpacecrafCharacteristicsTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...rafCharacteristicsTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
66
    use SpacecraftStateTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft...it\SpacecraftStateTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
67
    use SpacecraftHrefTrait;
0 ignored issues
show
Bug introduced by
The trait Stu\Component\Spacecraft\Trait\SpacecraftHrefTrait requires the property $value which is not provided by Stu\Orm\Entity\Spacecraft.
Loading history...
68
69
    #[Id]
70
    #[Column(type: 'integer')]
71
    #[GeneratedValue(strategy: 'IDENTITY')]
72
    private ?int $id = null;
73
74
    #[Column(type: 'integer')]
75
    private int $user_id = 0;
76
77
    #[Column(type: 'integer')]
78
    private int $rump_id = 0;
0 ignored issues
show
introduced by
The private property $rump_id is not used, and could be removed.
Loading history...
79
80
    #[Column(type: 'integer', nullable: true)]
81
    private ?int $plan_id = null;
0 ignored issues
show
introduced by
The private property $plan_id is not used, and could be removed.
Loading history...
82
83
    #[Column(type: 'string')]
84
    private string $name = '';
85
86
    #[Column(type: 'integer', length: 6)]
87
    private int $max_huelle = 0;
88
89
    #[Column(type: 'integer', length: 6)]
90
    private int $max_schilde = 0;
91
92
    #[Column(type: 'integer', nullable: true)]
93
    private ?int $tractored_ship_id = null;
0 ignored issues
show
introduced by
The private property $tractored_ship_id is not used, and could be removed.
Loading history...
94
95
    #[Column(type: 'integer', nullable: true)]
96
    private ?int $holding_web_id = null;
0 ignored issues
show
introduced by
The private property $holding_web_id is not used, and could be removed.
Loading history...
97
98
    #[Column(type: 'integer', nullable: true)]
99
    private ?int $database_id = null;
100
101
    #[Column(type: 'integer')]
102
    private int $location_id = 0;
0 ignored issues
show
introduced by
The private property $location_id is not used, and could be removed.
Loading history...
103
104
    #[OneToOne(targetEntity: 'SpacecraftCondition', mappedBy: 'spacecraft', cascade: ['all'])]
105
    private SpacecraftConditionInterface $condition;
106
107
    #[OneToOne(targetEntity: 'Ship')]
108
    #[JoinColumn(name: 'tractored_ship_id', referencedColumnName: 'id')]
109
    private ?ShipInterface $tractoredShip = null;
110
111
    #[ManyToOne(targetEntity: 'TholianWeb')]
112
    #[JoinColumn(name: 'holding_web_id', referencedColumnName: 'id')]
113
    private ?TholianWebInterface $holdingWeb = null;
114
115
    #[ManyToOne(targetEntity: 'User')]
116
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
117
    private UserInterface $user;
118
119
    /**
120
     * @var ArrayCollection<int, CrewAssignmentInterface>
121
     */
122
    #[OneToMany(targetEntity: 'CrewAssignment', mappedBy: 'spacecraft', indexBy: 'crew_id')]
123
    #[OrderBy(['crew' => 'ASC'])]
124
    private Collection $crew;
125
126
    #[OneToOne(targetEntity: 'TorpedoStorage', mappedBy: 'spacecraft')]
127
    private ?TorpedoStorageInterface $torpedoStorage = null;
128
129
    /**
130
     * @var ArrayCollection<int, SpacecraftSystemInterface>
131
     */
132
    #[OneToMany(targetEntity: 'SpacecraftSystem', mappedBy: 'spacecraft', indexBy: 'system_type')]
133
    #[OrderBy(['system_type' => 'ASC'])]
134
    private Collection $systems;
135
136
    #[ManyToOne(targetEntity: 'SpacecraftRump')]
137
    #[JoinColumn(name: 'rump_id', referencedColumnName: 'id')]
138
    private SpacecraftRumpInterface $rump;
139
140
    #[ManyToOne(targetEntity: 'SpacecraftBuildplan')]
141
    #[JoinColumn(name: 'plan_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
142
    private ?SpacecraftBuildplanInterface $buildplan = null;
143
144
    /**
145
     * @var ArrayCollection<int, StorageInterface>
146
     */
147
    #[OneToMany(targetEntity: 'Storage', mappedBy: 'spacecraft', indexBy: 'commodity_id')]
148
    #[OrderBy(['commodity_id' => 'ASC'])]
149
    private Collection $storage;
150
151
    #[ManyToOne(targetEntity: 'Location')]
152
    #[JoinColumn(name: 'location_id', referencedColumnName: 'id')]
153
    private LocationInterface $location;
154
155
    /**
156
     * @var ArrayCollection<int, ShipLogInterface>
157
     */
158
    #[OneToMany(targetEntity: 'ShipLog', mappedBy: 'spacecraft', fetch: 'EXTRA_LAZY')]
159
    #[OrderBy(['id' => 'DESC'])]
160
    private Collection $logbook;
161
162
    #[OneToOne(targetEntity: 'ShipTakeover', mappedBy: 'source')]
163
    private ?ShipTakeoverInterface $takeoverActive = null;
164
165
    #[OneToOne(targetEntity: 'ShipTakeover', mappedBy: 'target')]
166
    private ?ShipTakeoverInterface $takeoverPassive = null;
167
168 3
    public function __construct(SpacecraftConditionInterface $condition)
169
    {
170 3
        $this->crew = new ArrayCollection();
171 3
        $this->systems = new ArrayCollection();
172 3
        $this->storage = new ArrayCollection();
173 3
        $this->logbook = new ArrayCollection();
174
175 3
        $this->condition = $condition;
176
    }
177
178 43
    #[Override]
179
    public function getId(): int
180
    {
181 43
        if ($this->id === null) {
182
            throw new RuntimeException(sprintf('entity "%s" not yet persisted', $this->getName()));
183
        }
184
185 43
        return $this->id;
186
    }
187
188 15
    #[Override]
189
    public function getCondition(): SpacecraftConditionInterface
190
    {
191 15
        return $this->condition;
192
    }
193
194 1
    #[Override]
195
    public function getUserId(): int
196
    {
197 1
        return $this->user_id;
198
    }
199
200 7
    #[Override]
201
    public function getUserName(): string
202
    {
203 7
        return $this->getUser()->getName();
204
    }
205
206 35
    #[Override]
207
    public function getName(): string
208
    {
209 35
        return $this->name;
210
    }
211
212
    #[Override]
213
    public function setName(string $name): SpacecraftInterface
214
    {
215
        $this->name = $name;
216
        return $this;
217
    }
218
219 15
    #[Override]
220
    public function getMaxHull(): int
221
    {
222 15
        return $this->max_huelle;
223
    }
224
225
    #[Override]
226
    public function setMaxHuell(int $maxHull): SpacecraftInterface
227
    {
228
        $this->max_huelle = $maxHull;
229
        return $this;
230
    }
231
232
    #[Override]
233
    public function setMaxShield(int $maxShields): SpacecraftInterface
234
    {
235
        $this->max_schilde = $maxShields;
236
        return $this;
237
    }
238
239 1
    #[Override]
240
    public function getDatabaseId(): ?int
241
    {
242 1
        return $this->database_id;
243
    }
244
245
    #[Override]
246
    public function setDatabaseId(?int $databaseEntryId): SpacecraftInterface
247
    {
248
        $this->database_id = $databaseEntryId;
249
        return $this;
250
    }
251
252 13
    #[Override]
253
    public function getCrewAssignments(): Collection
254
    {
255 13
        return $this->crew;
256
    }
257
258 47
    #[Override]
259
    public function getUser(): UserInterface
260
    {
261 47
        return $this->user;
262
    }
263
264
    #[Override]
265
    public function setUser(UserInterface $user): SpacecraftInterface
266
    {
267
        $this->user = $user;
268
        return $this;
269
    }
270
271 2
    #[Override]
272
    public function getModules(): array
273
    {
274 2
        $modules = [];
275
276 2
        $buildplan = $this->getBuildplan();
277 2
        if ($buildplan === null) {
278
            return $modules;
279
        }
280
281 2
        foreach ($buildplan->getModulesOrdered() as $obj) {
282 2
            $module = $obj->getModule();
283 2
            $index = $module->getType() === SpacecraftModuleTypeEnum::SPECIAL ? $module->getId() : $module->getType()->value;
284 2
            $modules[$index] = $module;
285
        }
286
287 2
        return $modules;
288
    }
289
290 3
    #[Override]
291
    public function getTorpedoStorage(): ?TorpedoStorageInterface
292
    {
293 3
        return $this->torpedoStorage;
294
    }
295
296
    #[Override]
297
    public function setTorpedoStorage(?TorpedoStorageInterface $torpedoStorage): SpacecraftInterface
298
    {
299
        $this->torpedoStorage = $torpedoStorage;
300
        return $this;
301
    }
302
303 15
    #[Override]
304
    public function getStorage(): Collection
305
    {
306 15
        return $this->storage;
307
    }
308
309 39
    #[Override]
310
    public function getLocation(): MapInterface|StarSystemMapInterface
311
    {
312
        if (
313 39
            $this->location instanceof MapInterface
314 39
            || $this->location instanceof StarSystemMapInterface
315
        ) {
316 39
            return $this->location;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->location returns the type Stu\Orm\Entity\LocationInterface which includes types incompatible with the type-hinted return Stu\Orm\Entity\MapInterf...\StarSystemMapInterface.
Loading history...
317
        }
318
319
        throw new RuntimeException('unknown type');
320
    }
321
322 1
    #[Override]
323
    public function getLogbook(): Collection
324
    {
325 1
        return $this->logbook;
326
    }
327
328 4
    #[Override]
329
    public function getTakeoverActive(): ?ShipTakeoverInterface
330
    {
331 4
        return $this->takeoverActive;
332
    }
333
334
    #[Override]
335
    public function setTakeoverActive(?ShipTakeoverInterface $takeover): SpacecraftInterface
336
    {
337
        $this->takeoverActive = $takeover;
338
339
        return $this;
340
    }
341
342 4
    #[Override]
343
    public function getTakeoverPassive(): ?ShipTakeoverInterface
344
    {
345 4
        return $this->takeoverPassive;
346
    }
347
348
    #[Override]
349
    public function setTakeoverPassive(?ShipTakeoverInterface $takeover): SpacecraftInterface
350
    {
351
        $this->takeoverPassive = $takeover;
352
353
        return $this;
354
    }
355
356 3
    #[Override]
357
    public function setLocation(LocationInterface $location): SpacecraftInterface
358
    {
359 3
        $this->location = $location;
360
361 3
        return $this;
362
    }
363
364 13
    #[Override]
365
    public function getBuildplan(): ?SpacecraftBuildplanInterface
366
    {
367 13
        return $this->buildplan;
368
    }
369
370
    #[Override]
371
    public function setBuildplan(?SpacecraftBuildplanInterface $spacecraftBuildplan): SpacecraftInterface
372
    {
373
        $this->buildplan = $spacecraftBuildplan;
374
        return $this;
375
    }
376
377 41
    #[Override]
378
    public function getSystems(): Collection
379
    {
380 41
        return $this->systems;
381
    }
382
383 2
    #[Override]
384
    public function getTractoredShip(): ?ShipInterface
385
    {
386 2
        return $this->tractoredShip;
387
    }
388
389
    #[Override]
390
    public function setTractoredShip(?ShipInterface $ship): SpacecraftInterface
391
    {
392
        $this->tractoredShip = $ship;
393
        return $this;
394
    }
395
396 8
    #[Override]
397
    public function getHoldingWeb(): ?TholianWebInterface
398
    {
399 8
        return $this->holdingWeb;
400
    }
401
402
    #[Override]
403
    public function setHoldingWeb(?TholianWebInterface $web): SpacecraftInterface
404
    {
405
        $this->holdingWeb = $web;
406
407
        return $this;
408
    }
409
410 36
    #[Override]
411
    public function getRump(): SpacecraftRumpInterface
412
    {
413 36
        return $this->rump;
414
    }
415
416 19
    #[Override]
417
    public function getRumpId(): int
418
    {
419 19
        return $this->getRump()->getId();
420
    }
421
422 19
    #[Override]
423
    public function getRumpName(): string
424
    {
425 19
        return $this->getRump()->getName();
426
    }
427
428
    #[Override]
429
    public function setRump(SpacecraftRumpInterface $shipRump): SpacecraftInterface
430
    {
431
        $this->rump = $shipRump;
432
        return $this;
433
    }
434
435 5
    #[Override]
436
    public function getState(): SpacecraftStateEnum
437
    {
438 5
        return $this->condition->getState();
439
    }
440
441
    #[Override]
442
    public function __toString(): string
443
    {
444
        if ($this->id !== null) {
445
            return sprintf(
446
                "id: %d, name: %s",
447
                $this->getId(),
448
                $this->getName()
449
            );
450
        }
451
452
        return $this->getName();
453
    }
454
}
455