Fixed   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A discount() 0 10 2
A displayValue() 0 8 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 Fixed.
11
 */
12
class Fixed implements CouponContract
13
{
14
    use CouponTrait;
15
16
    public $code;
17
    public $value;
18
19
    /**
20
     * Fixed constructor.
21
     *
22
     * @param $code
23
     * @param $value
24
     * @param array $options
25
     */
26
    public function __construct($code, $value, $options = [])
27
    {
28
        $this->code = $code;
29
        $this->value = $value;
30
31
        $this->setOptions($options);
32
    }
33
34
    /**
35
     * Gets the discount amount.
36
     *
37
     * @param $throwErrors boolean this allows us to capture errors in our code if we wish,
38
     * that way we can spit out why the coupon has failed
39
     *
40
     * @return string
41
     */
42
    public function discount($throwErrors = false)
43
    {
44
        $total = app(LaraCart::SERVICE)->subTotal(false) - $this->value;
45
46
        if ($total < 0) {
47
            return 0;
48
        }
49
50
        return $this->value;
51
    }
52
53
    /**
54
     * Displays the value in a money format.
55
     *
56
     * @param null $locale
57
     * @param null $internationalFormat
58
     *
59
     * @return string
60
     */
61
    public function displayValue($locale = null, $internationalFormat = null)
62
    {
63
        return LaraCart::formatMoney(
64
            $this->discount(),
65
            $locale,
66
            $internationalFormat
67
        );
68
    }
69
}
70