Failed Conditions
Branch modify-scrutinizeryml (08dddf)
by Kentaro
10:04
created

CartItem::setProductClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.9666
c 0
b 0
f 0
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
Unused Code introduced by
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 78
    public function isDeliveryFee()
150
    {
151 78
        return false;
152
    }
153
154
    /**
155
     * 手数料明細かどうか.
156
     *
157
     * @return boolean 手数料明細の場合 true
158
     */
159 78
    public function isCharge()
160
    {
161 78
        return false;
162
    }
163
164
    /**
165
     * 値引き明細かどうか.
166
     *
167
     * @return boolean 値引き明細の場合 true
168
     */
169 78
    public function isDiscount()
170
    {
171 78
        return false;
172
    }
173
174
    /**
175
     * 税額明細かどうか.
176
     *
177
     * @return boolean 税額明細の場合 true
178
     */
179
    public function isTax()
180
    {
181
        return false;
182
    }
183
184 18
    public function getOrderItemType()
185
    {
186
        // TODO OrderItemType::PRODUCT
187 18
        $ItemType = new \Eccube\Entity\Master\OrderItemType();
188
189 18
        return $ItemType;
190
    }
191
192
    /**
193
     * @param ProductClass $ProductClass
194
     *
195
     * @return $this
196
     */
197 110
    public function setProductClass(ProductClass $ProductClass)
198
    {
199 110
        $this->ProductClass = $ProductClass;
200
201 110
        $this->product_class_id = is_object($ProductClass) ?
202 110
            $ProductClass->getId() : null;
203
204 110
        return $this;
205
    }
206
207
    /**
208
     * @return ProductClass
209
     */
210 102
    public function getProductClass()
211
    {
212 102
        return $this->ProductClass;
213
    }
214
215
    /**
216
     * @return int|null
217
     */
218 37
    public function getProductClassId()
219
    {
220 37
        return $this->product_class_id;
221
    }
222
223 79
    public function getPriceIncTax()
224
    {
225
        // TODO ItemInterfaceに追加, Cart::priceは税込み金額が入っているので,フィールドを分ける必要がある
226 79
        return $this->price;
227
    }
228
229
    /**
230
     * @return Cart
231
     */
232
    public function getCart()
233
    {
234
        return $this->Cart;
235
    }
236
237
    /**
238
     * @param Cart $Cart
239
     */
240 87
    public function setCart(Cart $Cart)
241
    {
242 87
        $this->Cart = $Cart;
243
    }
244
}
245