Passed
Push — master ( 66afc8...ff3c83 )
by Janko
09:01
created

Storage::setEntity()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 8
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 14
ccs 0
cts 9
cp 0
crap 20
rs 10
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\OneToOne;
15
use Doctrine\ORM\Mapping\Table;
16
use Stu\Lib\Transfer\EntityWithStorageInterface;
17
use Stu\Orm\Attribute\TruncateOnGameReset;
18
use Stu\Orm\Repository\StorageRepository;
19
20
#[Table(name: 'stu_storage')]
21
#[Index(name: 'storage_user_idx', columns: ['user_id'])]
22
#[Index(name: 'storage_commodity_idx', columns: ['commodity_id'])]
23
#[Index(name: 'storage_colony_idx', columns: ['colony_id'])]
24
#[Index(name: 'storage_spacecraft_idx', columns: ['spacecraft_id'])]
25
#[Index(name: 'storage_torpedo_idx', columns: ['torpedo_storage_id'])]
26
#[Index(name: 'storage_tradepost_idx', columns: ['tradepost_id'])]
27
#[Index(name: 'storage_tradeoffer_idx', columns: ['tradeoffer_id'])]
28
#[Entity(repositoryClass: StorageRepository::class)]
29
#[TruncateOnGameReset]
30
class Storage
31
{
32
    #[Id]
33
    #[Column(type: 'integer')]
34
    #[GeneratedValue(strategy: 'IDENTITY')]
35
    private int $id;
36
37
    #[Column(type: 'integer')]
38
    private int $user_id;
39
40
    #[Column(type: 'integer')]
41
    private int $commodity_id = 0;
42
43
    //TODO rename to amount
44
    #[Column(type: 'integer')]
45
    private int $count = 0;
46
47
    #[Column(type: 'integer', nullable: true)]
48
    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...
49
50
    #[Column(type: 'integer', nullable: true)]
51
    private ?int $spacecraft_id = null;
0 ignored issues
show
introduced by
The private property $spacecraft_id is not used, and could be removed.
Loading history...
52
53
    #[Column(type: 'integer', nullable: true)]
54
    private ?int $torpedo_storage_id = null;
0 ignored issues
show
introduced by
The private property $torpedo_storage_id is not used, and could be removed.
Loading history...
55
56
    #[Column(type: 'integer', nullable: true)]
57
    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...
58
59
    #[Column(type: 'integer', nullable: true)]
60
    private ?int $tradeoffer_id = null;
0 ignored issues
show
introduced by
The private property $tradeoffer_id is not used, and could be removed.
Loading history...
61
62
    #[Column(type: 'integer', nullable: true)]
63
    private ?int $trumfield_id = null;
0 ignored issues
show
introduced by
The private property $trumfield_id is not used, and could be removed.
Loading history...
64
65
    #[ManyToOne(targetEntity: User::class)]
66
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
67
    private ?User $user = null;
68
69
    #[ManyToOne(targetEntity: Commodity::class)]
70
    #[JoinColumn(name: 'commodity_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
71
    private Commodity $commodity;
72
73
    #[ManyToOne(targetEntity: Colony::class, inversedBy: 'storage')]
74
    #[JoinColumn(name: 'colony_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
75
    private ?Colony $colony = null;
76
77
    #[ManyToOne(targetEntity: Spacecraft::class, inversedBy: 'storage')]
78
    #[JoinColumn(name: 'spacecraft_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
79
    private ?Spacecraft $spacecraft = null;
80
81
    #[OneToOne(targetEntity: TorpedoStorage::class, inversedBy: 'storage')]
82
    #[JoinColumn(name: 'torpedo_storage_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
83
    private ?TorpedoStorage $torpedoStorage = null;
84
85
    #[ManyToOne(targetEntity: TradePost::class)]
86
    #[JoinColumn(name: 'tradepost_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
87
    private ?TradePost $tradePost = null;
88
89
    #[OneToOne(targetEntity: TradeOffer::class, inversedBy: 'storage')]
90
    #[JoinColumn(name: 'tradeoffer_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
91
    private ?TradeOffer $tradeOffer = null;
92
93
    #[ManyToOne(targetEntity: Trumfield::class, inversedBy: 'storage')]
94
    #[JoinColumn(name: 'trumfield_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
95
    private ?Trumfield $trumfield = null;
96
97
    public function getId(): int
98
    {
99
        return $this->id;
100
    }
101
102
    public function getUserId(): int
103
    {
104
        return $this->user_id;
105
    }
106
107
    public function setUser(User $user): Storage
108
    {
109
        $this->user = $user;
110
111
        return $this;
112
    }
113
114
    public function getCommodityId(): int
115
    {
116
        return $this->commodity_id;
117
    }
118
119 23
    public function getAmount(): int
120
    {
121 23
        return $this->count;
122
    }
123
124
    public function setAmount(int $amount): Storage
125
    {
126
        $this->count = $amount;
127
128
        return $this;
129
    }
130
131 12
    public function getCommodity(): Commodity
132
    {
133 12
        return $this->commodity;
134
    }
135
136
    public function setCommodity(Commodity $commodity): Storage
137
    {
138
        $this->commodity = $commodity;
139
140
        return $this;
141
    }
142
143
    public function getColony(): ?Colony
144
    {
145
        return $this->colony;
146
    }
147
148
    public function getSpacecraft(): ?Spacecraft
149
    {
150
        return $this->spacecraft;
151
    }
152
153
    public function setEntity(?EntityWithStorageInterface $entity): Storage
154
    {
155
        if ($entity === null) {
156
            $this->spacecraft = null;
157
            $this->colony = null;
158
        }
159
        if ($entity instanceof Spacecraft) {
160
            $this->spacecraft = $entity;
161
        }
162
        if ($entity instanceof Colony) {
163
            $this->colony = $entity;
164
        }
165
166
        return $this;
167
    }
168
169
    public function getTorpedoStorage(): ?TorpedoStorage
170
    {
171
        return $this->torpedoStorage;
172
    }
173
174
    public function setTorpedoStorage(TorpedoStorage $torpedoStorage): Storage
175
    {
176
        $this->torpedoStorage = $torpedoStorage;
177
        return $this;
178
    }
179
180
    public function getTradePost(): ?TradePost
181
    {
182
        return $this->tradePost;
183
    }
184
185
    public function setTradePost(TradePost $tradePost): Storage
186
    {
187
        $this->tradePost = $tradePost;
188
        return $this;
189
    }
190
191
    public function getTradeOffer(): ?TradeOffer
192
    {
193
        return $this->tradeOffer;
194
    }
195
196
    public function setTradeOffer(TradeOffer $tradeOffer): Storage
197
    {
198
        $this->tradeOffer = $tradeOffer;
199
        return $this;
200
    }
201
202
    public function setTrumfield(Trumfield $trumfield): Storage
203
    {
204
        $this->trumfield = $trumfield;
205
        return $this;
206
    }
207
}
208