Percentage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
namespace LukePOLO\LaraCart\Coupons;
4
5
use LukePOLO\LaraCart\Contracts\CouponContract;
6
use LukePOLO\LaraCart\LaraCart;
7
use LukePOLO\LaraCart\Traits\CouponTrait;
8
9
/**
10
 * Class Percentage.
11
 */
12
13
/**
14
 * Class Percentage.
15
 */
16
class Percentage implements CouponContract
17
{
18
    use CouponTrait;
19
20
    public $code;
21
    public $value;
22
23
    /**
24
     * Percentage constructor.
25
     *
26
     * @param $code
27
     * @param $value
28
     * @param array $options
29
     */
30
    public function __construct($code, $value, $options = [])
31
    {
32
        $this->code = $code;
33
        $this->value = $value;
34
35
        $this->setOptions($options);
36
    }
37
38
    /**
39
     * Gets the discount amount.
40
     *
41
     * @param $throwErrors boolean this allows us to capture errors in our code if we wish,
42
     * that way we can spit out why the coupon has failed
43
     *
44
     * @return string
45
     */
46
    public function discount($throwErrors = false)
47
    {
48
        return LaraCart::formatMoney(
49
            app(LaraCart::SERVICE)->subTotal(false) * $this->value,
50
            null,
51
            null,
52
            false
53
        );
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function displayValue()
60
    {
61
        return ($this->value * 100).'%';
62
    }
63
}
64