Passed
Push — dev ( 7914d2...bbc331 )
by Janko
10:29
created

Deals::getGiveCommodityAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
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\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\JoinColumn;
14
use Doctrine\ORM\Mapping\ManyToOne;
15
use Doctrine\ORM\Mapping\OneToMany;
16
use Doctrine\ORM\Mapping\OrderBy;
17
use Doctrine\ORM\Mapping\Table;
18
use Stu\Orm\Repository\DealsRepository;
19
20
#[Table(name: 'stu_deals')]
21
#[Entity(repositoryClass: DealsRepository::class)]
22
class Deals
23
{
24
    #[Id]
25
    #[Column(type: 'integer')]
26
    #[GeneratedValue(strategy: 'IDENTITY')]
27
    private int $id;
28
29
    #[Column(type: 'boolean')]
30
    private bool $auction = false;
31
32
    #[Column(type: 'integer', nullable: true)]
33
    private ?int $amount = 0;
34
35
    #[Column(type: 'integer', nullable: true)]
36
    private ?int $give_commodity = null;
37
38
    #[Column(type: 'integer', nullable: true)]
39
    private ?int $want_commodity = null;
40
41
    #[Column(type: 'integer', nullable: true)]
42
    private ?int $give_commodity_amonut = null;
43
44
    #[Column(type: 'integer', nullable: true)]
45
    private ?int $want_commodity_amount = null;
46
47
    #[Column(type: 'integer', nullable: true)]
48
    private ?int $want_prestige = null;
49
50
    #[Column(type: 'integer', nullable: true)]
51
    private ?int $buildplan_id = null;
52
53
    #[Column(type: 'boolean', nullable: true)]
54
    private ?bool $ship = null;
55
56
    #[Column(type: 'integer')]
57
    private int $start;
58
59
    #[Column(type: 'integer')]
60
    private int $end;
61
62
    #[Column(type: 'integer', nullable: true)]
63
    private ?int $taken_time = null;
64
65
    #[Column(type: 'integer', nullable: true)]
66
    private ?int $auction_user = null;
67
68
    #[Column(type: 'integer', nullable: true)]
69
    private ?int $auction_amount = null;
70
71
    #[ManyToOne(targetEntity: Commodity::class)]
72
    #[JoinColumn(name: 'want_commodity', referencedColumnName: 'id', onDelete: 'CASCADE')]
73
    private ?Commodity $wantedCommodity;
74
75
    #[ManyToOne(targetEntity: Commodity::class)]
76
    #[JoinColumn(name: 'give_commodity', referencedColumnName: 'id', onDelete: 'CASCADE')]
77
    private ?Commodity $giveCommodity;
78
79
    #[ManyToOne(targetEntity: SpacecraftBuildplan::class)]
80
    #[JoinColumn(name: 'buildplan_id', referencedColumnName: 'id')]
81
    private ?SpacecraftBuildplan $buildplan = null;
82
83
    #[ManyToOne(targetEntity: Faction::class)]
84
    #[JoinColumn(name: 'faction_id', referencedColumnName: 'id')]
85
    private ?Faction $faction;
0 ignored issues
show
introduced by
The private property $faction is not used, and could be removed.
Loading history...
86
87
    /**
88
     * @var ArrayCollection<int, AuctionBid>
89
     */
90
    #[OneToMany(targetEntity: AuctionBid::class, mappedBy: 'auction')]
91
    #[OrderBy(['max_amount' => 'ASC'])]
92
    private Collection $auctionBids;
93
94
    public function __construct()
95
    {
96
        $this->auctionBids = new ArrayCollection();
97
    }
98
99
    public function getId(): int
100
    {
101
        return $this->id;
102
    }
103
104
    public function setAuction(bool $auction): Deals
105
    {
106
        $this->auction = $auction;
107
108
        return $this;
109
    }
110
111
    public function getAuction(): bool
112
    {
113
        return $this->auction;
114
    }
115
116
    public function getAmount(): ?int
117
    {
118
        return $this->amount;
119
    }
120
121
122
    public function setAmount(int $amount): Deals
123
    {
124
        $this->amount = $amount;
125
126
        return $this;
127
    }
128
129
    public function getGiveCommodityId(): ?int
130
    {
131
        return $this->give_commodity;
132
    }
133
134
    public function getWantCommodityId(): ?int
135
    {
136
        return $this->want_commodity;
137
    }
138
139
    public function getGiveCommodityAmount(): ?int
140
    {
141
        return $this->give_commodity_amonut;
142
    }
143
144
145
    public function getWantCommodityAmount(): ?int
146
    {
147
        return $this->want_commodity_amount;
148
    }
149
150
    public function getWantPrestige(): ?int
151
    {
152
        return $this->want_prestige;
153
    }
154
155
    public function setwantPrestige(int $wantprestige): Deals
156
    {
157
        $this->want_prestige = $wantprestige;
158
159
        return $this;
160
    }
161
162
    public function getBuildplanId(): ?int
163
    {
164
        return $this->buildplan_id;
165
    }
166
167
    public function setBuildplanId(int $buildplanid): Deals
168
    {
169
        $this->buildplan_id = $buildplanid;
170
171
        return $this;
172
    }
173
174
    public function getShip(): ?bool
175
    {
176
        return $this->ship;
177
    }
178
179
    public function setShip(bool $ship): Deals
180
    {
181
        $this->ship = $ship;
182
183
        return $this;
184
    }
185
186
    public function getStart(): int
187
    {
188
        return $this->start;
189
    }
190
191
    public function getEnd(): int
192
    {
193
        return $this->end;
194
    }
195
196
    public function setEnd(int $end): Deals
197
    {
198
        $this->end = $end;
199
200
        return $this;
201
    }
202
203
    public function getTakenTime(): ?int
204
    {
205
        return $this->taken_time;
206
    }
207
208
    public function setTakenTime(int $time): Deals
209
    {
210
        $this->taken_time = $time;
211
212
        return $this;
213
    }
214
215
    public function getAuctionAmount(): ?int
216
    {
217
        return $this->auction_amount;
218
    }
219
220
    public function setAuctionAmount(int $auction_amount): Deals
221
    {
222
        $this->auction_amount = $auction_amount;
223
224
        return $this;
225
    }
226
227
    public function getAuctionUser(): ?User
228
    {
229
        $highestBid = $this->getHighestBid();
230
231
        return $highestBid !== null ? $highestBid->getUser() : null;
232
    }
233
234
    public function setAuctionUser(int $auction_user): Deals
235
    {
236
        $this->auction_user = $auction_user;
237
238
        return $this;
239
    }
240
241
    public function getWantedCommodity(): ?Commodity
242
    {
243
        return $this->wantedCommodity;
244
    }
245
246
    public function setWantedCommodity(?Commodity $wantedCommodity): Deals
247
    {
248
        $this->wantedCommodity = $wantedCommodity;
249
250
        return $this;
251
    }
252
253
    public function getGiveCommodity(): ?Commodity
254
    {
255
        return $this->giveCommodity;
256
    }
257
258
    public function setGiveCommodity(?Commodity $giveCommodity): Deals
259
    {
260
        $this->giveCommodity = $giveCommodity;
261
262
        return $this;
263
    }
264
265
    /**
266
     * @return array<int, Module>
267
     */
268
    public function getModules(): array
269
    {
270
        return $this->getBuildplan()?->getModules()
271
            ->map(fn(BuildplanModule $buildplanModule): Module => $buildplanModule->getModule())
272
            ->toArray() ?? [];
273
    }
274
275
    public function getBuildplan(): ?SpacecraftBuildplan
276
    {
277
        return $this->buildplan;
278
    }
279
280
    public function getRumpId(): int
281
    {
282
        return $this->getBuildplan()?->getRumpId() ?? 0;
283
    }
284
285
    public function getCrew(): int
286
    {
287
        return $this->getBuildplan()?->getCrew() ?? 0;
288
    }
289
290
    public function getBuildplanName(): string
291
    {
292
        return $this->getBuildplan()?->getName() ?? '';
293
    }
294
295
    /**
296
     * @return Collection<int, AuctionBid>
297
     */
298
    public function getAuctionBids(): Collection
299
    {
300
        return $this->auctionBids;
301
    }
302
303
    public function getHighestBid(): ?AuctionBid
304
    {
305
        $last = $this->getAuctionBids()->last();
306
307
        return $last === false ? null : $last;
308
    }
309
310
    public function isPrestigeCost(): bool
311
    {
312
        return $this->getWantPrestige() !== null;
313
    }
314
}
315