Passed
Push — master ( 5a11dc...578008 )
by Janko
08:39
created

CrewAssignment   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Test Coverage

Coverage 7.41%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 62
c 1
b 1
f 0
dl 0
loc 145
ccs 4
cts 54
cp 0.0741
rs 10
wmc 22

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getSlot() 0 3 1
A setSlot() 0 5 1
A assign() 0 13 4
A setRepairTask() 0 4 1
A setUser() 0 4 1
A getUser() 0 3 1
A getTradepost() 0 3 1
A setCrew() 0 5 1
A clearAssignment() 0 17 4
A setColony() 0 5 1
A getSpacecraft() 0 3 1
A getColony() 0 3 1
A getCrew() 0 3 1
A getRepairTask() 0 3 1
A setSpacecraft() 0 4 1
A setTradepost() 0 5 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\Id;
10
use Doctrine\ORM\Mapping\JoinColumn;
11
use Doctrine\ORM\Mapping\ManyToOne;
12
use Doctrine\ORM\Mapping\OneToOne;
13
use Doctrine\ORM\Mapping\Table;
14
use Stu\Component\Crew\CrewTypeEnum;
15
use Stu\Module\Spacecraft\Lib\Crew\EntityWithCrewAssignmentsInterface;
16
use Stu\Orm\Repository\CrewAssignmentRepository;
17
18
#[Table(name: 'stu_crew_assign')]
19
#[Entity(repositoryClass: CrewAssignmentRepository::class)]
20
class CrewAssignment
21
{
22
    #[Id]
23
    #[OneToOne(targetEntity: Crew::class)]
24
    #[JoinColumn(name: 'crew_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
25
    private Crew $crew;
26
27
    #[Column(type: 'smallint', nullable: true, enumType: CrewTypeEnum::class)]
28
    private ?CrewTypeEnum $slot = null;
29
30
    #[ManyToOne(targetEntity: Spacecraft::class)]
31
    #[JoinColumn(name: 'spacecraft_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
32
    private ?Spacecraft $spacecraft = null;
33
34
    #[ManyToOne(targetEntity: Colony::class)]
35
    #[JoinColumn(name: 'colony_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
36
    private ?Colony $colony = null;
37
38
    #[ManyToOne(targetEntity: TradePost::class)]
39
    #[JoinColumn(name: 'tradepost_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
40
    private ?TradePost $tradepost = null;
41
42
    #[ManyToOne(targetEntity: User::class)]
43
    #[JoinColumn(name: 'user_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
44
    private User $user;
45
46
    #[ManyToOne(targetEntity: RepairTask::class)]
47
    #[JoinColumn(name: 'repair_task_id', referencedColumnName: 'id')]
48
    private ?RepairTask $repairTask = null;
49
50 2
    public function getSlot(): ?CrewTypeEnum
51
    {
52 2
        return $this->slot;
53
    }
54
55
    public function setSlot(?CrewTypeEnum $slot): CrewAssignment
56
    {
57
        $this->slot = $slot;
58
59
        return $this;
60
    }
61
62
    public function getUser(): User
63
    {
64
        return $this->user;
65
    }
66
67
    public function setUser(User $user): CrewAssignment
68
    {
69
        $this->user = $user;
70
        return $this;
71
    }
72
73
    public function getRepairTask(): ?RepairTask
74
    {
75
        return $this->repairTask;
76
    }
77
78
    public function setRepairTask(?RepairTask $repairTask): CrewAssignment
79
    {
80
        $this->repairTask = $repairTask;
81
        return $this;
82
    }
83
84 5
    public function getCrew(): Crew
85
    {
86 5
        return $this->crew;
87
    }
88
89
    public function setCrew(Crew $crew): CrewAssignment
90
    {
91
        $this->crew = $crew;
92
93
        return $this;
94
    }
95
96
    public function getSpacecraft(): ?Spacecraft
97
    {
98
        return $this->spacecraft;
99
    }
100
101
    public function setSpacecraft(?Spacecraft $spacecraft): CrewAssignment
102
    {
103
        $this->spacecraft = $spacecraft;
104
        return $this;
105
    }
106
107
    public function getColony(): ?Colony
108
    {
109
        return $this->colony;
110
    }
111
112
    public function setColony(?Colony $colony): CrewAssignment
113
    {
114
        $this->colony = $colony;
115
116
        return $this;
117
    }
118
119
    public function getTradepost(): ?TradePost
120
    {
121
        return $this->tradepost;
122
    }
123
124
    public function setTradepost(?TradePost $tradepost): CrewAssignment
125
    {
126
        $this->tradepost = $tradepost;
127
128
        return $this;
129
    }
130
131
    public function clearAssignment(): CrewAssignment
132
    {
133
        if ($this->spacecraft !== null) {
134
            $this->spacecraft->getCrewAssignments()->removeElement($this);
135
        }
136
        if ($this->colony !== null) {
137
            $this->colony->getCrewAssignments()->removeElement($this);
138
        }
139
        if ($this->tradepost !== null) {
140
            $this->tradepost->getCrewAssignments()->removeElement($this);
141
        }
142
143
        $this->spacecraft = null;
144
        $this->colony = null;
145
        $this->tradepost = null;
146
147
        return $this;
148
    }
149
150
    public function assign(EntityWithCrewAssignmentsInterface $target): CrewAssignment
151
    {
152
        if ($target instanceof Colony) {
153
            $this->setColony($target);
154
        }
155
        if ($target instanceof Spacecraft) {
156
            $this->setSpacecraft($target);
157
        }
158
        if ($target instanceof TradePost) {
159
            $this->setTradepost($target);
160
        }
161
162
        return $this;
163
    }
164
}
165