Passed
Pull Request — master (#2138)
by Janko
24:59 queued 14:00
created

Spacecraft::setTakeoverPassive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
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 6
ccs 0
cts 3
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\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 6
    public function __construct()
169
    {
170 6
        $this->crew = new ArrayCollection();
171 6
        $this->systems = new ArrayCollection();
172 6
        $this->storage = new ArrayCollection();
173 6
        $this->logbook = new ArrayCollection();
174
    }
175
176 43
    #[Override]
177
    public function getId(): int
178
    {
179 43
        if ($this->id === null) {
180
            throw new RuntimeException(sprintf('entity "%s" not yet persisted', $this->getName()));
181
        }
182
183 43
        return $this->id;
184
    }
185
186 18
    #[Override]
187
    public function getCondition(): SpacecraftConditionInterface
188
    {
189 18
        return $this->condition;
190
    }
191
192 3
    #[Override]
193
    public function setCondition(SpacecraftConditionInterface $condition): SpacecraftInterface
194
    {
195 3
        $this->condition = $condition;
196
197 3
        return $this;
198
    }
199
200 1
    #[Override]
201
    public function getUserId(): int
202
    {
203 1
        return $this->user_id;
204
    }
205
206 7
    #[Override]
207
    public function getUserName(): string
208
    {
209 7
        return $this->getUser()->getName();
210
    }
211
212 35
    #[Override]
213
    public function getName(): string
214
    {
215 35
        return $this->name;
216
    }
217
218
    #[Override]
219
    public function setName(string $name): SpacecraftInterface
220
    {
221
        $this->name = $name;
222
        return $this;
223
    }
224
225 15
    #[Override]
226
    public function getMaxHull(): int
227
    {
228 15
        return $this->max_huelle;
229
    }
230
231
    #[Override]
232
    public function setMaxHuell(int $maxHull): SpacecraftInterface
233
    {
234
        $this->max_huelle = $maxHull;
235
        return $this;
236
    }
237
238
    #[Override]
239
    public function setMaxShield(int $maxShields): SpacecraftInterface
240
    {
241
        $this->max_schilde = $maxShields;
242
        return $this;
243
    }
244
245 1
    #[Override]
246
    public function getDatabaseId(): ?int
247
    {
248 1
        return $this->database_id;
249
    }
250
251
    #[Override]
252
    public function setDatabaseId(?int $databaseEntryId): SpacecraftInterface
253
    {
254
        $this->database_id = $databaseEntryId;
255
        return $this;
256
    }
257
258 13
    #[Override]
259
    public function getCrewAssignments(): Collection
260
    {
261 13
        return $this->crew;
262
    }
263
264 47
    #[Override]
265
    public function getUser(): UserInterface
266
    {
267 47
        return $this->user;
268
    }
269
270
    #[Override]
271
    public function setUser(UserInterface $user): SpacecraftInterface
272
    {
273
        $this->user = $user;
274
        return $this;
275
    }
276
277 2
    #[Override]
278
    public function getModules(): array
279
    {
280 2
        $modules = [];
281
282 2
        $buildplan = $this->getBuildplan();
283 2
        if ($buildplan === null) {
284
            return $modules;
285
        }
286
287 2
        foreach ($buildplan->getModulesOrdered() as $obj) {
288 2
            $module = $obj->getModule();
289 2
            $index = $module->getType() === SpacecraftModuleTypeEnum::SPECIAL ? $module->getId() : $module->getType()->value;
290 2
            $modules[$index] = $module;
291
        }
292
293 2
        return $modules;
294
    }
295
296 3
    #[Override]
297
    public function getTorpedoStorage(): ?TorpedoStorageInterface
298
    {
299 3
        return $this->torpedoStorage;
300
    }
301
302
    #[Override]
303
    public function setTorpedoStorage(?TorpedoStorageInterface $torpedoStorage): SpacecraftInterface
304
    {
305
        $this->torpedoStorage = $torpedoStorage;
306
        return $this;
307
    }
308
309 15
    #[Override]
310
    public function getStorage(): Collection
311
    {
312 15
        return $this->storage;
313
    }
314
315 39
    #[Override]
316
    public function getLocation(): MapInterface|StarSystemMapInterface
317
    {
318
        if (
319 39
            $this->location instanceof MapInterface
320 39
            || $this->location instanceof StarSystemMapInterface
321
        ) {
322 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...
323
        }
324
325
        throw new RuntimeException('unknown type');
326
    }
327
328 1
    #[Override]
329
    public function getLogbook(): Collection
330
    {
331 1
        return $this->logbook;
332
    }
333
334 4
    #[Override]
335
    public function getTakeoverActive(): ?ShipTakeoverInterface
336
    {
337 4
        return $this->takeoverActive;
338
    }
339
340
    #[Override]
341
    public function setTakeoverActive(?ShipTakeoverInterface $takeover): SpacecraftInterface
342
    {
343
        $this->takeoverActive = $takeover;
344
345
        return $this;
346
    }
347
348 4
    #[Override]
349
    public function getTakeoverPassive(): ?ShipTakeoverInterface
350
    {
351 4
        return $this->takeoverPassive;
352
    }
353
354
    #[Override]
355
    public function setTakeoverPassive(?ShipTakeoverInterface $takeover): SpacecraftInterface
356
    {
357
        $this->takeoverPassive = $takeover;
358
359
        return $this;
360
    }
361
362 3
    #[Override]
363
    public function setLocation(LocationInterface $location): SpacecraftInterface
364
    {
365 3
        $this->location = $location;
366
367 3
        return $this;
368
    }
369
370 13
    #[Override]
371
    public function getBuildplan(): ?SpacecraftBuildplanInterface
372
    {
373 13
        return $this->buildplan;
374
    }
375
376
    #[Override]
377
    public function setBuildplan(?SpacecraftBuildplanInterface $spacecraftBuildplan): SpacecraftInterface
378
    {
379
        $this->buildplan = $spacecraftBuildplan;
380
        return $this;
381
    }
382
383 41
    #[Override]
384
    public function getSystems(): Collection
385
    {
386 41
        return $this->systems;
387
    }
388
389 2
    #[Override]
390
    public function getTractoredShip(): ?ShipInterface
391
    {
392 2
        return $this->tractoredShip;
393
    }
394
395
    #[Override]
396
    public function setTractoredShip(?ShipInterface $ship): SpacecraftInterface
397
    {
398
        $this->tractoredShip = $ship;
399
        return $this;
400
    }
401
402 8
    #[Override]
403
    public function getHoldingWeb(): ?TholianWebInterface
404
    {
405 8
        return $this->holdingWeb;
406
    }
407
408
    #[Override]
409
    public function setHoldingWeb(?TholianWebInterface $web): SpacecraftInterface
410
    {
411
        $this->holdingWeb = $web;
412
413
        return $this;
414
    }
415
416 36
    #[Override]
417
    public function getRump(): SpacecraftRumpInterface
418
    {
419 36
        return $this->rump;
420
    }
421
422 19
    #[Override]
423
    public function getRumpId(): int
424
    {
425 19
        return $this->getRump()->getId();
426
    }
427
428 19
    #[Override]
429
    public function getRumpName(): string
430
    {
431 19
        return $this->getRump()->getName();
432
    }
433
434
    #[Override]
435
    public function setRump(SpacecraftRumpInterface $shipRump): SpacecraftInterface
436
    {
437
        $this->rump = $shipRump;
438
        return $this;
439
    }
440
441 5
    #[Override]
442
    public function getState(): SpacecraftStateEnum
443
    {
444 5
        return $this->condition->getState();
445
    }
446
447
    #[Override]
448
    public function __toString(): string
449
    {
450
        if ($this->id !== null) {
451
            return sprintf(
452
                "id: %d, name: %s",
453
                $this->getId(),
454
                $this->getName()
455
            );
456
        }
457
458
        return $this->getName();
459
    }
460
}
461