FlatTax   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 50
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A value() 0 9 2
1
<?php
2
3
namespace SilverShop\Model\Modifiers\Tax;
4
5
use SilverShop\Model\Order;
6
7
/**
8
 * Handles calculation of sales tax on Orders.
9
 *
10
 * @package    shop
11
 * @subpackage modifiers
12
 */
13
class FlatTax extends Base
14
{
15
    /**
16
     * @config
17
     * @var string
18
     */
19
    private static $name            = 'GST';
0 ignored issues
show
introduced by
The private property $name is not used, and could be removed.
Loading history...
20
21
    /**
22
     * @config
23
     * @var float
24
     */
25
    private static $rate            = 0.15;
26
27
    /**
28
     * @config
29
     * @var bool
30
     */
31
    private static $exclusive       = true;
32
33
    /**
34
     * @config
35
     * @var string
36
     */
37
    private static $includedmessage = '%.1f%% %s (inclusive)';
0 ignored issues
show
introduced by
The private property $includedmessage is not used, and could be removed.
Loading history...
38
39
    /**
40
     * @config
41
     * @var string
42
     */
43
    private static $excludedmessage = '%.1f%% %s';
0 ignored issues
show
introduced by
The private property $excludedmessage is not used, and could be removed.
Loading history...
44
45
    public function __construct($record = null, $isSingleton = false, $model = null)
46
    {
47
        parent::__construct($record, $isSingleton, $model);
48
        $this->Type = self::config()->exclusive ? 'Chargable' : 'Ignored';
0 ignored issues
show
Documentation Bug introduced by
It seems like self::config()->exclusiv...'Chargable' : 'Ignored' of type string is incompatible with the declared type SilverStripe\ORM\FieldType\DBEnum of property $Type.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
    }
50
51
    /**
52
     * Get the tax amount to charge on the order.
53
     */
54
    public function value($incoming)
55
    {
56
        $this->Rate = self::config()->rate;
57
        //inclusive tax requires a different calculation
58
        return self::config()->exclusive
59
            ?
60
            $incoming * $this->Rate
61
            :
62
            $incoming - round($incoming / (1 + $this->Rate), Order::config()->rounding_precision);
63
    }
64
}
65