Passed
Push — dev ( 0f0480...7566e1 )
by Janko
11:01
created

CrewAssignment   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 213
Duplicated Lines 0 %

Test Coverage

Coverage 12.7%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 107
c 1
b 1
f 0
dl 0
loc 213
ccs 8
cts 63
cp 0.127
rs 10
wmc 26

20 Methods

Rating   Name   Duplication   Size   Complexity  
A setRepairTask() 0 5 1
A getId() 0 4 1
A setUser() 0 5 1
A getUser() 0 4 1
A getSlot() 0 4 1
A setCrew() 0 6 1
A getUserId() 0 4 1
A getSpacecraft() 0 4 1
A getCrewId() 0 4 1
A getCrew() 0 4 1
A getRepairTask() 0 4 1
A setSlot() 0 6 1
A getPosition() 0 4 1
A assign() 0 14 4
A getTradepost() 0 4 1
A clearAssignment() 0 18 4
A setColony() 0 6 1
A getColony() 0 4 1
A setSpacecraft() 0 6 1
A setTradepost() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\Index;
12
use Doctrine\ORM\Mapping\JoinColumn;
13
use Doctrine\ORM\Mapping\ManyToOne;
14
use Doctrine\ORM\Mapping\Table;
15
use Doctrine\ORM\Mapping\UniqueConstraint;
16
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...
17
use Stu\Component\Crew\CrewEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Crew\CrewEnum 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...
18
use Stu\Module\Spacecraft\Lib\Crew\EntityWithCrewAssignmentsInterface;
19
use Stu\Orm\Repository\CrewAssignmentRepository;
20
21
//TODO RENAME to CrewAssignment, indices, repo and stuff
22
#[Table(name: 'stu_crew_assign')]
23
#[Index(name: 'ship_crew_colony_idx', columns: ['colony_id'])]
24
#[Index(name: 'ship_crew_spacecraft_idx', columns: ['spacecraft_id'])]
25
#[Index(name: 'ship_crew_tradepost_idx', columns: ['tradepost_id'])]
26
#[Index(name: 'ship_crew_user_idx', columns: ['user_id'])]
27
#[UniqueConstraint(name: 'ship_crew_crew_idx', columns: ['crew_id'])]
28
#[Entity(repositoryClass: CrewAssignmentRepository::class)]
29
class CrewAssignment implements CrewAssignmentInterface
30
{
31
    #[Id]
32
    #[Column(type: 'integer')]
33
    #[GeneratedValue(strategy: 'IDENTITY')]
34
    private int $id;
35
36
    #[Column(type: 'integer', nullable: true)]
37
    private ?int $spacecraft_id = 0;
38
39
    #[Column(type: 'integer', nullable: true)]
40
    private ?int $colony_id = null;
0 ignored issues
show
introduced by
The private property $colony_id is not used, and could be removed.
Loading history...
41
42
    #[Column(type: 'integer', nullable: true)]
43
    private ?int $tradepost_id = null;
0 ignored issues
show
introduced by
The private property $tradepost_id is not used, and could be removed.
Loading history...
44
45
    #[Column(type: 'integer')]
46
    private int $crew_id = 0;
47
48
    #[Column(type: 'smallint', nullable: true)]
49
    private ?int $slot = null;
50
51
    #[Column(type: 'integer')]
52
    private int $user_id = 0;
53
54
    #[Column(type: 'integer', nullable: true)]
55
    private ?int $repair_task_id = null;
0 ignored issues
show
introduced by
The private property $repair_task_id is not used, and could be removed.
Loading history...
56
57
    #[ManyToOne(targetEntity: 'Crew')]
58
    #[JoinColumn(name: 'crew_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
59
    private CrewInterface $crew;
60
61
    #[ManyToOne(targetEntity: 'Spacecraft')]
62
    #[JoinColumn(name: 'spacecraft_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
63
    private ?SpacecraftInterface $spacecraft = null;
64
65
    #[ManyToOne(targetEntity: 'Colony')]
66
    #[JoinColumn(name: 'colony_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
67
    private ?ColonyInterface $colony = null;
68
69
    #[ManyToOne(targetEntity: 'TradePost')]
70
    #[JoinColumn(name: 'tradepost_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
71
    private ?TradePostInterface $tradepost = null;
72
73
    #[ManyToOne(targetEntity: 'User')]
74
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
75
    private UserInterface $user;
76
77
    #[ManyToOne(targetEntity: 'RepairTask')]
78
    #[JoinColumn(name: 'repair_task_id', referencedColumnName: 'id')]
79
    private ?RepairTaskInterface $repairTask = null;
80
81 1
    #[Override]
82
    public function getId(): int
83
    {
84 1
        return $this->id;
85
    }
86
87
    #[Override]
88
    public function getCrewId(): int
89
    {
90
        return $this->crew_id;
91
    }
92
93 2
    #[Override]
94
    public function getSlot(): ?int
95
    {
96 2
        return $this->slot;
97
    }
98
99
    #[Override]
100
    public function setSlot(?int $slot): CrewAssignmentInterface
101
    {
102
        $this->slot = $slot;
103
104
        return $this;
105
    }
106
107 1
    #[Override]
108
    public function getPosition(): string
109
    {
110 1
        return CrewEnum::getDescription($this->getSlot());
111
    }
112
113
    #[Override]
114
    public function getUserId(): int
115
    {
116
        return $this->user_id;
117
    }
118
119
    #[Override]
120
    public function getUser(): UserInterface
121
    {
122
        return $this->user;
123
    }
124
125
    #[Override]
126
    public function setUser(UserInterface $user): CrewAssignmentInterface
127
    {
128
        $this->user = $user;
129
        return $this;
130
    }
131
132
    #[Override]
133
    public function getRepairTask(): ?RepairTaskInterface
134
    {
135
        return $this->repairTask;
136
    }
137
138
    #[Override]
139
    public function setRepairTask(?RepairTaskInterface $repairTask): CrewAssignmentInterface
140
    {
141
        $this->repairTask = $repairTask;
142
        return $this;
143
    }
144
145 5
    #[Override]
146
    public function getCrew(): CrewInterface
147
    {
148 5
        return $this->crew;
149
    }
150
151
    #[Override]
152
    public function setCrew(CrewInterface $crew): CrewAssignmentInterface
153
    {
154
        $this->crew = $crew;
155
156
        return $this;
157
    }
158
159
    #[Override]
160
    public function getSpacecraft(): ?SpacecraftInterface
161
    {
162
        return $this->spacecraft;
163
    }
164
165
    #[Override]
166
    public function setSpacecraft(?SpacecraftInterface $spacecraft): CrewAssignmentInterface
167
    {
168
        $this->spacecraft_id = null;
169
        $this->spacecraft = $spacecraft;
170
        return $this;
171
    }
172
173
    #[Override]
174
    public function getColony(): ?ColonyInterface
175
    {
176
        return $this->colony;
177
    }
178
179
    #[Override]
180
    public function setColony(?ColonyInterface $colony): CrewAssignmentInterface
181
    {
182
        $this->colony = $colony;
183
184
        return $this;
185
    }
186
187
    #[Override]
188
    public function getTradepost(): ?TradePostInterface
189
    {
190
        return $this->tradepost;
191
    }
192
193
    #[Override]
194
    public function setTradepost(?TradePostInterface $tradepost): CrewAssignmentInterface
195
    {
196
        $this->tradepost = $tradepost;
197
198
        return $this;
199
    }
200
201
    #[Override]
202
    public function clearAssignment(): CrewAssignmentInterface
203
    {
204
        if ($this->spacecraft !== null) {
205
            $this->spacecraft->getCrewAssignments()->removeElement($this);
206
        }
207
        if ($this->colony !== null) {
208
            $this->colony->getCrewAssignments()->removeElement($this);
209
        }
210
        if ($this->tradepost !== null) {
211
            $this->tradepost->getCrewAssignments()->removeElement($this);
212
        }
213
214
        $this->spacecraft = null;
215
        $this->colony = null;
216
        $this->tradepost = null;
217
218
        return $this;
219
    }
220
221
    #[Override]
222
    public function assign(EntityWithCrewAssignmentsInterface $target): CrewAssignmentInterface
223
    {
224
        if ($target instanceof ColonyInterface) {
225
            $this->setColony($target);
226
        }
227
        if ($target instanceof SpacecraftInterface) {
228
            $this->setSpacecraft($target);
229
        }
230
        if ($target instanceof TradePostInterface) {
231
            $this->setTradepost($target);
232
        }
233
234
        return $this;
235
    }
236
}
237