Completed
Push — master ( c2b43f...7517d8 )
by Jan
03:46
created

PartLot::setPart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * part-db version 0.1
5
 * Copyright (C) 2005 Christoph Lechner
6
 * http://www.cl-projects.de/
7
 *
8
 * part-db version 0.2+
9
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
10
 * http://code.google.com/p/part-db/
11
 *
12
 * Part-DB Version 0.4+
13
 * Copyright (C) 2016 - 2019 Jan Böhmer
14
 * https://github.com/jbtronics
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
29
 *
30
 */
31
32
namespace App\Entity\Parts;
33
34
35
use App\Entity\Base\DBElement;
36
use App\Entity\Base\NamedDBElement;
37
use App\Entity\Base\TimestampTrait;
38
use App\Validator\Constraints\Selectable;
39
use Doctrine\ORM\Mapping as ORM;
40
use Symfony\Component\Validator\Constraints as Assert;
41
42
/**
43
 * This entity describes a lot where parts can be stored.
44
 * It is the connection between a part and its store locations.
45
 * @package App\Entity\Parts
46
 * @ORM\Entity()
47
 * @ORM\Table(name="part_lots")
48
 * @ORM\HasLifecycleCallbacks()
49
 */
50
class PartLot extends DBElement
51
{
52
53
    use TimestampTrait;
54
55
    /**
56
     * @var string A short description about this lot, shown in table
57
     * @ORM\Column(type="text")
58
     */
59
    protected $description;
60
61
    /**
62
     * @var string A comment stored with this lot.
63
     * @ORM\Column(type="text")
64
     */
65
    protected $comment;
66
67
    /**
68
     * @var ?\DateTime Set a time until when the lot must be used.
69
     * Set to null, if the lot can be used indefinitley.
70
     * @ORM\Column(type="datetimetz", name="expiration_date", nullable=true)
71
     */
72
    protected $expiration_date;
73
74
    /**
75
     * @var Storelocation The storelocation of this lot
76
     * @ORM\ManyToOne(targetEntity="Storelocation")
77
     * @ORM\JoinColumn(name="id_store_location", referencedColumnName="id")
78
     * @Selectable()
79
     */
80
    protected $storage_location;
81
82
    /**
83
     * @var Part The part that is stored in this lot
84
     * @ORM\ManyToOne(targetEntity="Part", inversedBy="partLots")
85
     * @ORM\JoinColumn(name="id_part", referencedColumnName="id")
86
     */
87
    protected $part;
88
89
    /**
90
     * @var bool If this is set to true, the instock amount is marked as not known
91
     * @ORM\Column(type="boolean")
92
     */
93
    protected $instock_unknown;
94
95
96
    /**
97
     * @var float For continuos sizes (length, volume, etc.) the instock is saved here.
98
     * @ORM\Column(type="float")
99
     * @Assert\Positive()
100
     */
101
    protected $amount;
102
103
    /**
104
     * @var boolean Determines if this lot was manually marked for refilling.
105
     * @ORM\Column(type="boolean")
106
     */
107
    protected $needs_refill;
108
109
    /**
110
     * Returns the ID as an string, defined by the element class.
111
     * This should have a form like P000014, for a part with ID 14.
112
     *
113
     * @return string The ID as a string;
114
     *
115
     */
116
    public function getIDString(): string
117
    {
118
        return 'PL' . $this->getID();
119
    }
120
121
    /**
122
     * Check if the current part lot is expired.
123
     * This is the case, if the expiration date is greater the the current date.
124
     * @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
125
     * @throws \Exception
126
     */
127
    public function isExpired(): ?bool
128
    {
129
        if ($this->expiration_date == null) {
130
            return null;
131
        }
132
133
        //Check if the expiration date is bigger then current time
134
        return $this->expiration_date < new \DateTime();
135
    }
136
137
    /**
138
     * Gets the description of the part lot. Similar to a "name" of the part lot.
139
     * @return string
140
     */
141
    public function getDescription(): string
142
    {
143
        return $this->description;
144
    }
145
146
    /**
147
     * Sets the description of the part lot.
148
     * @param string $description
149
     * @return PartLot
150
     */
151
    public function setDescription(string $description): PartLot
152
    {
153
        $this->description = $description;
154
        return $this;
155
    }
156
157
    /**
158
     * Gets the comment for this part lot.
159
     * @return string
160
     */
161
    public function getComment(): string
162
    {
163
        return $this->comment;
164
    }
165
166
    /**
167
     * Sets the comment for this part lot.
168
     * @param string $comment
169
     * @return PartLot
170
     */
171
    public function setComment(string $comment): PartLot
172
    {
173
        $this->comment = $comment;
174
        return $this;
175
    }
176
177
    /**
178
     * Gets the expiration date for the part lot. Returns null, if no expiration date was set.
179
     * @return \DateTime|null
180
     */
181
    public function getExpirationDate(): ?\DateTime
182
    {
183
        return $this->expiration_date;
184
    }
185
186
    /**
187
     * Sets the expiration date for the part lot. Set to null, if the part lot does not expires.
188
     * @param \DateTime $expiration_date
189
     * @return PartLot
190
     */
191
    public function setExpirationDate(?\DateTime $expiration_date): PartLot
192
    {
193
        $this->expiration_date = $expiration_date;
194
        return $this;
195
    }
196
197
    /**
198
     * Gets the storage locatiion, where this part lot is stored.
199
     * @return Storelocation The store location where this part is stored
200
     */
201
    public function getStorageLocation(): Storelocation
202
    {
203
        return $this->storage_location;
204
    }
205
206
    /**
207
     * Sets the storage location, where this part lot is stored
208
     * @param Storelocation $storage_location
209
     * @return PartLot
210
     */
211
    public function setStorageLocation(Storelocation $storage_location): PartLot
212
    {
213
        $this->storage_location = $storage_location;
214
        return $this;
215
    }
216
217
    /**
218
     * Return the part that is stored in this part lot.
219
     * @return Part
220
     */
221
    public function getPart(): Part
222
    {
223
        return $this->part;
224
    }
225
226
    /**
227
     * Sets the part that is stored in this part lot.
228
     * @param Part $part
229
     * @return PartLot
230
     */
231
    public function setPart(Part $part): PartLot
232
    {
233
        $this->part = $part;
234
        return $this;
235
    }
236
237
    /**
238
     * Checks if the instock value in the part lot is unknown.
239
     *
240
     * @return bool
241
     */
242
    public function isInstockUnknown(): bool
243
    {
244
        return $this->instock_unknown;
245
    }
246
247
    /**
248
     * Set the unknown instock status of this part lot.
249
     * @param bool $instock_unknown
250
     * @return PartLot
251
     */
252
    public function setInstockUnknown(bool $instock_unknown): PartLot
253
    {
254
        $this->instock_unknown = $instock_unknown;
255
        return $this;
256
    }
257
258
    /**
259
     * @return float
260
     */
261
    public function getAmount(): float
262
    {
263
        if (!$this->part->useFloatAmount()) {
264
            return round($this->amount);
265
        }
266
        return (float) $this->amount;
267
    }
268
269
    public function setAmount(float $new_amount): PartLot
270
    {
271
        $this->amount  = $new_amount;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return App\Entity\Parts\PartLot. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
272
    }
273
274
275
276
    /**
277
     * @return bool
278
     */
279
    public function isNeedsRefill(): bool
280
    {
281
        return $this->needs_refill;
282
    }
283
284
    /**
285
     * @param bool $needs_refill
286
     * @return PartLot
287
     */
288
    public function setNeedsRefill(bool $needs_refill): PartLot
289
    {
290
        $this->needs_refill = $needs_refill;
291
        return $this;
292
    }
293
294
295
}