Passed
Branch master (6bfc27)
by Dariusz
02:47 queued 26s
created

CartDiscount::formatPrice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Plane\Shop;
4
5
use Plane\Shop\PriceFormat\PriceFormatInterface;
6
7
/**
8
 * Discount class that can be applied to Cart
9
 *
10
 * @author Dariusz Korsak <[email protected]>
11
 * @package Plane\Shop
12
 */
13
class CartDiscount
14
{
15
    /**
16
     * Discount text
17
     * @var string
18
     */
19
    private $discountText;
20
    
21
    /**
22
     * Price after discount
23
     * @var int|float
24
     */
25
    private $priceAfterDiscount;
26
    
27
    /**
28
     * Price format object
29
     * @var \Plane\Shop\PriceFormat\PriceFormatInterface
30
     */
31
    private $priceFormat;
32
    
33
    /**
34
     * Set discount text
35
     * @param string $discountText
36
     */
37
    public function setDiscountText($discountText)
38
    {
39
        $this->discountText = $discountText;
40
    }
41
    
42
    /**
43
     * Set price after discount
44
     * @param double $priceAfterDiscount
45
     */
46
    public function setPriceAfterDiscount($priceAfterDiscount)
47
    {
48
        $this->priceAfterDiscount = $priceAfterDiscount;
49
    }
50
    
51
    /**
52
     * Return discount text
53
     * @return string
54
     */
55
    public function getDiscountText()
56
    {
57
        return $this->discountText;
58
    }
59
    
60
    /**
61
     * Return price after discount
62
     * @return int|float
63
     */
64
    public function getPriceAfterDiscount()
65
    {
66
        return $this->formatPrice($this->priceAfterDiscount);
67
    }
68
    
69
    /**
70
     * Set price format object
71
     * @param \Plane\Shop\PriceFormat\PriceFormatInterface $priceFormat
72
     */
73
    public function setPriceFormat(PriceFormatInterface $priceFormat)
74
    {
75
        $this->priceFormat = $priceFormat;
76
    }
77
    
78
    /**
79
     * Format price with set price format object
80
     * @param float $price
81
     * @return float
82
     */
83
    protected function formatPrice($price)
84
    {
85
        if (is_null($this->priceFormat)) {
86
            return $price;
87
        }
88
        
89
        return $this->priceFormat->formatPrice($price);
90
    }
91
}
92