Passed
Pull Request — dev (#2038)
by Janko
09:06
created

CrewAssignment::clearAssignment()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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