CartRow   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 49
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPrice() 0 4 1
A getMeal() 0 4 1
A addQuantity() 0 4 1
A getQuantity() 0 4 1
A setQuantity() 0 6 1
A toArray() 0 9 1
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