Deals::getTakenTime()   A
last analyzed

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