Percentage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 1
cbo 2
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A discount() 0 9 1
A displayValue() 0 4 1
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