OrderProduct   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 28
lcom 2
cbo 6
dl 0
loc 174
rs 10
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCurrentStock() 0 8 2
A getCurrentSellPrice() 0 8 2
A getCurrentWeight() 0 8 2
A getQuantity() 0 4 1
A setQuantity() 0 4 1
A increaseQuantity() 0 4 1
A decreaseQuantity() 0 4 1
A getSellPrice() 0 4 1
A setSellPrice() 0 4 1
A getBuyPrice() 0 4 1
A setBuyPrice() 0 4 1
A getWeight() 0 4 1
A setWeight() 0 4 1
A getOptions() 0 4 1
A setOptions() 0 4 1
A isLocked() 0 4 1
A setLocked() 0 4 1
A getOrder() 0 4 1
A setOrder() 0 4 1
A getProduct() 0 4 1
A setProduct() 0 4 1
A getVariant() 0 4 1
A setVariant() 0 4 1
A hasVariant() 0 4 1
1
<?php
2
3
namespace WellCommerce\Bundle\OrderBundle\Entity;
4
5
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
6
use WellCommerce\Bundle\AppBundle\Entity\DiscountablePrice;
7
use WellCommerce\Bundle\AppBundle\Entity\Price;
8
use WellCommerce\Bundle\CatalogBundle\Entity\Product;
9
use WellCommerce\Bundle\CatalogBundle\Entity\Variant;
10
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable;
11
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface;
12
use WellCommerce\Extra\OrderBundle\Entity\OrderProductExtraTrait;
13
14
/**
15
 * Class OrderProduct
16
 *
17
 * @author  Adam Piotrowski <[email protected]>
18
 */
19
class OrderProduct implements EntityInterface
20
{
21
    use Identifiable;
22
    use Timestampable;
23
    use OrderProductExtraTrait;
24
    
25
    protected $quantity = 1;
26
    protected $weight   = 0.00;
27
    protected $options  = [];
28
    protected $locked   = false;
29
    
30
    /**
31
     * @var Price
32
     */
33
    protected $buyPrice;
34
    
35
    /**
36
     * @var Price
37
     */
38
    protected $sellPrice;
39
    
40
    /**
41
     * @var Order
42
     */
43
    protected $order;
44
    
45
    /**
46
     * @var Product
47
     */
48
    protected $product;
49
    
50
    /**
51
     * @var Variant
52
     */
53
    protected $variant;
54
    
55
    public function __construct()
56
    {
57
        $this->buyPrice  = new Price();
58
        $this->sellPrice = new Price();
59
    }
60
    
61
    public function getCurrentStock(): int
62
    {
63
        if ($this->hasVariant()) {
64
            return $this->getVariant()->getStock();
65
        }
66
        
67
        return $this->getProduct()->getStock();
68
    }
69
    
70
    public function getCurrentSellPrice(): DiscountablePrice
71
    {
72
        if ($this->hasVariant()) {
73
            return $this->getVariant()->getSellPrice();
74
        }
75
        
76
        return $this->getProduct()->getSellPrice();
77
    }
78
    
79
    public function getCurrentWeight(): float
80
    {
81
        if ($this->hasVariant()) {
82
            return $this->getVariant()->getWeight();
83
        }
84
        
85
        return $this->getProduct()->getWeight();
86
    }
87
    
88
    public function getQuantity(): int
89
    {
90
        return $this->quantity;
91
    }
92
    
93
    public function setQuantity(int $quantity)
94
    {
95
        $this->quantity = $quantity;
96
    }
97
    
98
    public function increaseQuantity(int $increase)
99
    {
100
        $this->quantity += $increase;
101
    }
102
    
103
    public function decreaseQuantity(int $decrease)
104
    {
105
        $this->quantity -= $decrease;
106
    }
107
    
108
    public function getSellPrice(): Price
109
    {
110
        return $this->sellPrice;
111
    }
112
    
113
    public function setSellPrice(Price $sellPrice)
114
    {
115
        $this->sellPrice = $sellPrice;
116
    }
117
    
118
    public function getBuyPrice(): Price
119
    {
120
        return $this->buyPrice;
121
    }
122
    
123
    public function setBuyPrice(Price $buyPrice)
124
    {
125
        $this->buyPrice = $buyPrice;
126
    }
127
    
128
    public function getWeight(): float
129
    {
130
        return $this->weight;
131
    }
132
    
133
    public function setWeight(float $weight)
134
    {
135
        $this->weight = $weight;
136
    }
137
    
138
    public function getOptions(): array
139
    {
140
        return $this->options;
141
    }
142
    
143
    public function setOptions(array $options)
144
    {
145
        $this->options = $options;
146
    }
147
    
148
    public function isLocked(): bool
149
    {
150
        return $this->locked;
151
    }
152
    
153
    public function setLocked(bool $locked)
154
    {
155
        $this->locked = $locked;
156
    }
157
    
158
    public function getOrder(): Order
159
    {
160
        return $this->order;
161
    }
162
    
163
    public function setOrder(Order $order = null)
164
    {
165
        $this->order = $order;
166
    }
167
    
168
    public function getProduct(): Product
169
    {
170
        return $this->product;
171
    }
172
    
173
    public function setProduct(Product $product)
174
    {
175
        $this->product = $product;
176
    }
177
    
178
    public function getVariant()
179
    {
180
        return $this->variant;
181
    }
182
    
183
    public function setVariant(Variant $variant)
184
    {
185
        $this->variant = $variant;
186
    }
187
    
188
    public function hasVariant(): bool
189
    {
190
        return $this->variant instanceof Variant;
191
    }
192
}
193