CartRow::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Cart;
4
5
use AppBundle\Entity\Meal;
6
7
class CartRow
8
{
9
    private $meal;
10
11
    private $quantity;
12
13
    public function __construct(Meal $meal, $quantity = 1)
14
    {
15
        $this->meal = $meal;
16
        $this->quantity = (int) $quantity;
17
    }
18
19
    public function getPrice()
20
    {
21
        return $this->meal->getPrice()->mul($this->quantity);
22
    }
23
24
    public function getMeal()
25
    {
26
        return $this->meal;
27
    }
28
29
    public function addQuantity($quantity)
30
    {
31
        $this->quantity = (int) $this->quantity + $quantity;
32
    }
33
34
    public function getQuantity()
35
    {
36
        return $this->quantity;
37
    }
38
39
    public function setQuantity($quantity)
40
    {
41
        $this->quantity = (int) $quantity;
42
43
        return $this;
44
    }
45
46
    public function toArray()
47
    {
48
        return array(
49
            'meal' => $this->meal->getName(),
50
            'quantity' => $this->quantity,
51
            'unit_price' => $this->meal->getPrice()->toArray(),
52
            'price' => $this->getPrice()->toArray()
53
        );
54
    }
55
}
56