TaxModifier::getTableValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * PriceModifier.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 31/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
/**
12
 * Class TaxModifier
13
 *
14
 * Adds a configurable tax rate on the receipt
15
 *
16
 * @package Broarm\EventTickets
17
 */
18
class TaxModifier extends PriceModifier
19
{
20
    /**
21
     * Set the tax rate as a percentage
22
     *
23
     * @var string
24
     */
25
    private static $tax_rate = 21;
26
27
    /**
28
     * Set if the tax rate is inclusive or exclusive
29
     *
30
     * @var string
31
     */
32
    private static $inclusive = false;
33
34
    /**
35
     * Set the default sort value to a large int so it always shows and calculates as last
36
     *
37
     * @var array
38
     */
39
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
40
        'Title' => 'Tax modifier',
41
        'Sort' => 9999
42
    );
43
44
    /**
45
     * Update the total, if the tax is not inclusive the total gets altered
46
     *
47
     * @param float $total
48
     * @param Reservation $reservation
49
     */
50
    public function updateTotal(&$total, Reservation $reservation) {
51
        $rate = (float)self::config()->get('tax_rate') / 100;
52
        $tax = $total * $rate;
53
        $this->setPriceModification($tax);
54
        if (!(bool)self::config()->get('inclusive')) {
55
            $total += $tax;
56
        }
57
    }
58
59
    /**
60
     * Show the used tax rate in the table title
61
     *
62
     * @return string
63
     */
64
    public function getTableTitle()
65
    {
66
        $rate = _t(
67
            'TaxModifier.TABLE_TITLE',
68
            '{rate}% BTW',
69
            null,
70
            array(
0 ignored issues
show
Documentation introduced by
array('rate' => (double)...fig()->get('tax_rate')) is of type array<string,double,{"rate":"double"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
                'rate' => (float)self::config()->get('tax_rate')
72
            )
73
        );
74
75
        if ((bool)self::config()->get('inclusive')) {
76
            $inc = _t('TaxModifier.INCLUSIVE', '(Incl.)');
77
            $rate .= " $inc";
78
        }
79
80
        return $rate;
81
    }
82
83
    /**
84
     * Show the calculated tax value as a positive value
85
     *
86
     * @return float
87
     */
88
    public function getTableValue()
89
    {
90
        return $this->PriceModification;
91
    }
92
93
    /**
94
     * Create a tax modifier if it does not already exists
95
     *
96
     * @param Reservation $reservation
97
     *
98
     * @return TaxModifier|\DataObject|null|static
99
     */
100
    public static function findOrMake(Reservation $reservation)
101
    {
102
        if (!$modifier = $reservation->PriceModifiers()->find('ClassName', self::class)) {
103
            $modifier = self::create();
104
            $modifier->write();
105
        }
106
107
        return $modifier;
108
    }
109
}
110