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

src/Eccube/Entity/CartItem.php (3 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\ORM\Mapping as ORM;
17
18
/**
19
 * CartItem
20
 *
21
 * @ORM\Table(name="dtb_cart_item")
22
 * @ORM\InheritanceType("SINGLE_TABLE")
23
 * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
24
 * @ORM\HasLifecycleCallbacks()
25
 * @ORM\Entity(repositoryClass="Eccube\Repository\CartItemRepository")
26
 */
27
class CartItem extends \Eccube\Entity\AbstractEntity implements ItemInterface
28
{
29
    use PointRateTrait;
30
31
    /**
32
     * @var integer
33
     *
34
     * @ORM\Column(name="id", type="bigint", options={"unsigned":true})
35
     * @ORM\Id
36
     * @ORM\GeneratedValue(strategy="IDENTITY")
37
     */
38
    private $id;
0 ignored issues
show
The property $id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
40
    /**
41
     * @var string
42
     *
43
     * @ORM\Column(name="price", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
44
     */
45
    private $price = 0;
46
47
    /**
48
     * @var string
49
     *
50
     * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0})
51
     */
52
    private $quantity = 0;
53
54
    /**
55
     * @var \Eccube\Entity\ProductClass
56
     *
57
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass")
58
     * @ORM\JoinColumns({
59
     *   @ORM\JoinColumn(name="product_class_id", referencedColumnName="id")
60
     * })
61
     */
62
    private $ProductClass;
63
64
    /**
65
     * @var \Eccube\Entity\Cart
66
     *
67
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Cart", inversedBy="CartItems")
68
     * @ORM\JoinColumns({
69
     *   @ORM\JoinColumn(name="cart_id", referencedColumnName="id", onDelete="CASCADE")
70
     * })
71
     */
72
    private $Cart;
73
74
    /**
75
     * sessionのシリアライズのために使われる
76
     *
77
     * @var int
78
     */
79
    private $product_class_id;
80
81
    public function __sleep()
82
    {
83
        return ['product_class_id', 'price', 'quantity'];
84
    }
85
86
    /**
87
     * @param  integer  $price
88
     *
89
     * @return CartItem
90
     */
91 92
    public function setPrice($price)
92
    {
93 92
        $this->price = $price;
0 ignored issues
show
Documentation Bug introduced by
The property $price was declared of type string, but $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...
94
95 92
        return $this;
96
    }
97
98
    /**
99
     * @return string
100
     */
101 82
    public function getPrice()
102
    {
103 82
        return $this->price;
104
    }
105
106
    /**
107
     * @param  integer  $quantity
108
     *
109
     * @return CartItem
110
     */
111 95
    public function setQuantity($quantity)
112
    {
113 95
        $this->quantity = $quantity;
0 ignored issues
show
Documentation Bug introduced by
The property $quantity was declared of type string, but $quantity 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...
114
115 95
        return $this;
116
    }
117
118
    /**
119
     * @return string
120
     */
121 91
    public function getQuantity()
122
    {
123 91
        return $this->quantity;
124
    }
125
126
    /**
127
     * @return integer
128
     */
129 16
    public function getTotalPrice()
130
    {
131 16
        return $this->getPrice() * $this->getQuantity();
132
    }
133
134
    /**
135
     * 商品明細かどうか.
136
     *
137
     * @return boolean 商品明細の場合 true
138
     */
139 89
    public function isProduct()
140
    {
141 89
        return true;
142
    }
143
144
    /**
145
     * 送料明細かどうか.
146
     *
147
     * @return boolean 送料明細の場合 true
148
     */
149 79
    public function isDeliveryFee()
150
    {
151 79
        return false;
152
    }
153
154
    /**
155
     * 手数料明細かどうか.
156
     *
157
     * @return boolean 手数料明細の場合 true
158
     */
159 79
    public function isCharge()
160
    {
161 79
        return false;
162
    }
163
164
    /**
165
     * 値引き明細かどうか.
166
     *
167
     * @return boolean 値引き明細の場合 true
168
     */
169 79
    public function isDiscount()
170
    {
171 79
        return false;
172
    }
173
174
    /**
175
     * 税額明細かどうか.
176
     *
177
     * @return boolean 税額明細の場合 true
178
     */
179
    public function isTax()
180
    {
181
        return false;
182
    }
183
184
    /**
185
     * ポイント明細かどうか.
186
     *
187
     * @return boolean ポイント明細の場合 true
188
     */
189 79
    public function isPoint()
190
    {
191 79
        return false;
192
    }
193
194 17
    public function getOrderItemType()
195
    {
196
        // TODO OrderItemType::PRODUCT
197 17
        $ItemType = new \Eccube\Entity\Master\OrderItemType();
198
199 17
        return $ItemType;
200
    }
201
202
    /**
203
     * @param ProductClass $ProductClass
204
     *
205
     * @return $this
206
     */
207 110
    public function setProductClass(ProductClass $ProductClass)
208
    {
209 110
        $this->ProductClass = $ProductClass;
210
211 110
        $this->product_class_id = is_object($ProductClass) ?
212 110
            $ProductClass->getId() : null;
213
214 110
        return $this;
215
    }
216
217
    /**
218
     * @return ProductClass
219
     */
220 103
    public function getProductClass()
221
    {
222 103
        return $this->ProductClass;
223
    }
224
225
    /**
226
     * @return int|null
227
     */
228 37
    public function getProductClassId()
229
    {
230 37
        return $this->product_class_id;
231
    }
232
233 79
    public function getPriceIncTax()
234
    {
235
        // TODO ItemInterfaceに追加, Cart::priceは税込み金額が入っているので,フィールドを分ける必要がある
236 79
        return $this->price;
237
    }
238
239
    /**
240
     * @return Cart
241
     */
242
    public function getCart()
243
    {
244
        return $this->Cart;
245
    }
246
247
    /**
248
     * @param Cart $Cart
249
     */
250 88
    public function setCart(Cart $Cart)
251
    {
252 88
        $this->Cart = $Cart;
253
    }
254
}
255