Failed Conditions
Pull Request — experimental/sf (#3236)
by Kentaro
144:19 queued 116:23
created

src/Eccube/Entity/Cart.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Entity;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\ORM\Mapping as ORM;
18
use Eccube\Service\PurchaseFlow\InvalidItemException;
19
use Eccube\Service\PurchaseFlow\ItemCollection;
20
21
/**
22
 * Cart
23
 *
24
 * @ORM\Table(name="dtb_cart", indexes={@ORM\Index(name="dtb_cart_pre_order_id_idx", columns={"pre_order_id"}), @ORM\Index(name="dtb_cart_update_date_idx", columns={"update_date"})})
25
 * @ORM\InheritanceType("SINGLE_TABLE")
26
 * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
27
 * @ORM\HasLifecycleCallbacks()
28
 * @ORM\Entity(repositoryClass="Eccube\Repository\CartRepository")
29
 */
30
class Cart extends AbstractEntity implements PurchaseInterface, ItemHolderInterface
31
{
32
    use PointTrait;
33
34
    /**
35
     * @var integer
36
     *
37
     * @ORM\Column(name="id", type="bigint", options={"unsigned":true})
38
     * @ORM\Id
39
     * @ORM\GeneratedValue(strategy="IDENTITY")
40
     */
41
    private $id;
42
43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(name="cart_key", type="string", options={"unsigned":true}, nullable=true)
47
     * @ORM\GeneratedValue(strategy="IDENTITY")
48
     */
49
    private $cart_key;
50
51
    /**
52
     * @var \Eccube\Entity\Customer
53
     *
54
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer")
55
     * @ORM\JoinColumns({
56
     *   @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
57
     * })
58
     */
59
    private $Customer;
60
61
    /**
62
     * @var bool
63
     */
64
    private $lock = false;
65
66
    /**
67
     * @var \Doctrine\Common\Collections\Collection|CartItem[]
68
     *
69
     * @ORM\OneToMany(targetEntity="Eccube\Entity\CartItem", mappedBy="Cart", cascade={"persist"})
70
     */
71
    private $CartItems;
72
73
    /**
74
     * @var string|null
75
     *
76
     * @ORM\Column(name="pre_order_id", type="string", length=255, nullable=true)
77
     */
78
    private $pre_order_id = null;
79
80
    /**
81
     * @var string
82
     *
83
     * @ORM\Column(name="total_price", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
84
     */
85
    private $total_price;
86
87
    /**
88
     * @var string
89
     *
90
     * @ORM\Column(name="delivery_fee_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
91
     */
92
    private $delivery_fee_total;
93
94
    /**
95
     * @var \DateTime
96
     *
97
     * @ORM\Column(name="create_date", type="datetimetz")
98
     */
99
    private $create_date;
100
101
    /**
102
     * @var \DateTime
103
     *
104
     * @ORM\Column(name="update_date", type="datetimetz")
105
     */
106
    private $update_date;
107
108
    /**
109
     * @var InvalidItemException[]
110
     */
111
    private $errors = [];
112
113
    public function __wakeup()
114
    {
115
        $this->errors = [];
116
    }
117
118 100
    public function __construct()
119
    {
120 100
        $this->CartItems = new ArrayCollection();
121
    }
122
123
    /**
124
     * @return int
125
     */
126 2
    public function getId()
127
    {
128 2
        return $this->id;
129
    }
130
131
    /**
132
     * @return string
133
     */
134 78
    public function getCartKey()
135
    {
136 78
        return $this->cart_key;
137
    }
138
139
    /**
140
     * @param string $cartKey
141
     */
142 86
    public function setCartKey(string $cartKey)
143
    {
144 86
        $this->cart_key = $cartKey;
145
    }
146
147
    /**
148
     * @return bool
149
     *
150
     * @deprecated 使用しないので削除予定
151
     */
152
    public function getLock()
153
    {
154
        return $this->lock;
155
    }
156
157
    /**
158
     * @param  bool                $lock
159
     *
160
     * @return \Eccube\Entity\Cart
161
     *
162
     * @deprecated 使用しないので削除予定
163
     */
164
    public function setLock($lock)
165
    {
166
        $this->lock = $lock;
167
168
        return $this;
169
    }
170
171
    /**
172
     * @return string|null
173
     */
174 53
    public function getPreOrderId()
175
    {
176 53
        return $this->pre_order_id;
177
    }
178
179
    /**
180
     * @param  integer             $pre_order_id
181
     *
182
     * @return \Eccube\Entity\Cart
183
     */
184 54
    public function setPreOrderId($pre_order_id)
185
    {
186 54
        $this->pre_order_id = $pre_order_id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pre_order_id of type integer is incompatible with the declared type string|null of property $pre_order_id.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
187
188 54
        return $this;
189
    }
190
191
    /**
192
     * @param  CartItem            $CartItem
193
     *
194
     * @return \Eccube\Entity\Cart
195
     */
196 89
    public function addCartItem(CartItem $CartItem)
197
    {
198 89
        $this->CartItems[] = $CartItem;
199
200 89
        return $this;
201
    }
202
203
    /**
204
     * @return \Eccube\Entity\Cart
205
     */
206
    public function clearCartItems()
207
    {
208
        $this->CartItems->clear();
209
210
        return $this;
211
    }
212
213
    /**
214
     * @return ArrayCollection|CartItem[]
215
     */
216 95
    public function getCartItems()
217
    {
218 95
        return $this->CartItems;
219
    }
220
221
    /**
222
     * Alias of getCartItems()
223
     */
224 92
    public function getItems()
225
    {
226 92
        return (new ItemCollection($this->getCartItems()))->sort();
227
    }
228
229
    /**
230
     * @param  CartItem[]          $CartItems
231
     *
232
     * @return \Eccube\Entity\Cart
233
     */
234
    public function setCartItems($CartItems)
235
    {
236
        $this->CartItems = $CartItems;
237
238
        return $this;
239
    }
240
241
    /**
242
     * Set total.
243
     *
244
     * @param integer $total_price
245
     *
246
     * @return Cart
247
     */
248 87
    public function setTotalPrice($total_price)
249
    {
250 87
        $this->total_price = $total_price;
0 ignored issues
show
Documentation Bug introduced by
The property $total_price was declared of type string, but $total_price is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
251
252 87
        return $this;
253
    }
254
255
    /**
256
     * @return string
257
     */
258 80
    public function getTotalPrice()
259
    {
260 80
        return $this->total_price;
261
    }
262
263
    /**
264
     * Alias of setTotalPrice.
265
     */
266 85
    public function setTotal($total)
267
    {
268 85
        return $this->setTotalPrice($total);
269
    }
270
271
    /**
272
     * Alias of getTotalPrice
273
     */
274 80
    public function getTotal()
275
    {
276 80
        return $this->getTotalPrice();
277
    }
278
279
    /**
280
     * @return integer
281
     */
282 71
    public function getTotalQuantity()
283
    {
284 71
        $totalQuantity = 0;
285 71
        foreach ($this->CartItems as $CartItem) {
286 71
            $totalQuantity += $CartItem->getQuantity();
287
        }
288
289 71
        return $totalQuantity;
290
    }
291
292
    /**
293
     * @param ItemInterface $item
294
     */
295 3
    public function addItem(ItemInterface $item)
296
    {
297 3
        $this->CartItems->add($item);
298
    }
299
300
    /**
301
     * 個数の合計を返します。
302
     *
303
     * @return integer
304
     */
305 35
    public function getQuantity()
306
    {
307 35
        return $this->getTotalQuantity();
308
    }
309
310
    /**
311
     * {@inheritdoc}
312
     */
313 85
    public function setDeliveryFeeTotal($total)
314
    {
315 85
        $this->delivery_fee_total = $total;
316
317 85
        return $this;
318
    }
319
320
    /**
321
     * {@inheritdoc}
322
     */
323
    public function getDeliveryFeeTotal()
324
    {
325
        return $this->delivery_fee_total;
326
    }
327
328
    /**
329
     * @return Customer
330
     */
331
    public function getCustomer(): Customer
332
    {
333
        return $this->Customer;
334
    }
335
336
    /**
337
     * @param Customer $Customer
338
     */
339 78
    public function setCustomer(Customer $Customer = null)
340
    {
341 78
        $this->Customer = $Customer;
342
    }
343
344
    /**
345
     * Set createDate.
346
     *
347
     * @param \DateTime $createDate
348
     *
349
     * @return Cart
350
     */
351 80
    public function setCreateDate($createDate)
352
    {
353 80
        $this->create_date = $createDate;
354
355 80
        return $this;
356
    }
357
358
    /**
359
     * Get createDate.
360
     *
361
     * @return \DateTime
362
     */
363
    public function getCreateDate()
364
    {
365
        return $this->create_date;
366
    }
367
368
    /**
369
     * Set updateDate.
370
     *
371
     * @param \DateTime $updateDate
372
     *
373
     * @return Cart
374
     */
375 80
    public function setUpdateDate($updateDate)
376
    {
377 80
        $this->update_date = $updateDate;
378
379 80
        return $this;
380
    }
381
382
    /**
383
     * Get updateDate.
384
     *
385
     * @return \DateTime
386
     */
387
    public function getUpdateDate()
388
    {
389
        return $this->update_date;
390
    }
391
392
    /**
393
     * {@inheritdoc}
394
     */
395
    public function setDiscount($total)
396
    {
397
        // TODO quiet
398
    }
399
400
    /**
401
     * {@inheritdoc}
402
     */
403
    public function setCharge($total)
404
    {
405
        // TODO quiet
406
    }
407
408
    /**
409
     * {@inheritdoc}
410
     */
411
    public function setTax($total)
412
    {
413
        // TODO quiet
414
    }
415
}
416