Completed
Push — master ( 0d684b...49516e )
by Dariusz
03:16
created

Shipping::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Plane\Shop;
4
5
use Plane\Shop\PriceFormat\PriceFormatInterface;
6
7
/**
8
 * Description of Shipping
9
 *
10
 * @author Dariusz Korsak <[email protected]>
11
 * @package Plane/Shop
12
 */
13
class Shipping implements ShippingInterface
14
{
15
    /**
16
     * Shippint id
17
     * @var int
18
     */
19
    private $id;
20
    
21
    /**
22
     * Shippint name
23
     * @var string
24
     */
25
    private $name;
26
    
27
    /**
28
     * Shipping description
29
     * @var string
30
     */
31
    private $description;
32
    
33
    /**
34
     * Shipping cost
35
     * @var float
36
     */
37
    private $cost;
38
    
39
    /**
40
     * Price format object
41
     * @var \Plane\Shop\PriceFormat\PriceFormatInterface
42
     */
43
    private $priceFormat;
44
    
45
    /**
46
     * Constructor
47
     * @param array $data
48
     */
49 3
    public function __construct(array $data)
50
    {
51 3
        foreach ($data as $k => $v) {
52 3
            $this->$k = $v;
53 3
        }
54 3
    }
55
    
56
    /**
57
     * Return id
58
     * @return int
59
     */
60 1
    public function getId()
61
    {
62 1
        return $this->id;
63
    }
64
    
65
    /**
66
     * Return name
67
     * @return string
68
     */
69 1
    public function getName()
70
    {
71 1
        return $this->name;
72
    }
73
    
74
    /**
75
     * Return description
76
     * @return string
77
     */
78 1
    public function getDescription()
79
    {
80 1
        return $this->description;
81
    }
82
    
83
    /**
84
     * Return cost
85
     * @return float
86
     */
87 3
    public function getCost()
88
    {
89 3
        if (!is_null($this->priceFormat)) {
90 1
            return $this->priceFormat->formatPrice($this->cost);
91
        }
92
        
93 2
        return (float) $this->cost;
94
    }
95
    
96
    /**
97
     * Set cost
98
     * @param int|float $cost
99
     */
100 1
    public function setCost($cost)
101
    {
102 1
        $this->cost = (float) $cost;
103 1
    }
104
    
105
    /**
106
     * Set price format object
107
     * @param \Plane\Shop\PriceFormat\PriceFormatInterface $priceFormat
108
     */
109 1
    public function setPriceFormat(PriceFormatInterface $priceFormat)
110
    {
111 1
        $this->priceFormat = $priceFormat;
112 1
    }
113
}
114