Passed
Push — 1.0 ( c10284...283486 )
by Morven
02:02
created

TestProduct::getShowTaxString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SilverCommerce\TaxAdmin\Tests\Model;
4
5
use SilverStripe\i18n\i18n;
6
use SilverStripe\Dev\TestOnly;
7
use SilverStripe\ORM\DataObject;
8
use SilverCommerce\TaxAdmin\Model\TaxRate;
9
use SilverCommerce\TaxAdmin\Traits\Taxable;
10
use SilverCommerce\TaxAdmin\Model\TaxCategory;
11
use SilverCommerce\TaxAdmin\Interfaces\TaxableProvider;
12
13
class TestProduct extends DataObject implements TestOnly, TaxableProvider
14
{
15
    use Taxable;
0 ignored issues
show
Bug introduced by
The trait SilverCommerce\TaxAdmin\Traits\Taxable requires the property $Rate which is not provided by SilverCommerce\TaxAdmin\Tests\Model\TestProduct.
Loading history...
16
17
    /**
18
     * Default behaviour for price with tax (if current instance not set)
19
     *
20
     * @var boolean
21
     */
22
    private static $show_price_with_tax = false;
0 ignored issues
show
introduced by
The private property $show_price_with_tax is not used, and could be removed.
Loading history...
23
24
    /**
25
     * Default behaviour for adding the tax string to the rendered currency.
26
     *
27
     * @var boolean
28
     */
29
    private static $show_tax_string = false;
0 ignored issues
show
introduced by
The private property $show_tax_string is not used, and could be removed.
Loading history...
30
31
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
32
        "Title" => "Varchar",
33
        "BasePrice" => 'Decimal(9,3)',
34
        "StockID" => "Varchar"
35
    ];
36
37
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
38
        'TaxRate' => TaxRate::class,
39
        'TaxCategory' => TaxCategory::class
40
    ];
41
42
    public function getBasePrice()
43
    {
44
        return $this->dbObject('BasePrice')->getValue();
45
    }
46
47
    /**
48
     * Find a tax rate based on the selected ID, or revert to using the valid tax
49
     * from the current category
50
     *
51
     * @return \SilverCommerce\TaxAdmin\Model\TaxRate
52
     */
53
    public function getTaxRate()
54
    {
55
        $tax = TaxRate::get()->byID($this->getOwner()->TaxRateID);
0 ignored issues
show
Bug introduced by
The method getOwner() does not exist on SilverCommerce\TaxAdmin\Tests\Model\TestProduct. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $tax = TaxRate::get()->byID($this->/** @scrutinizer ignore-call */ getOwner()->TaxRateID);
Loading history...
56
57
        // If no tax explicity set, try to get from category
58
        if (empty($tax)) {
59
            $category = TaxCategory::get()->byID($this->getOwner()->TaxCategoryID);
60
61
            $tax = (!empty($category)) ? $category->ValidTax() : null ;
62
        }
63
64
        if (empty($tax)) {
65
            $tax = TaxRate::create();
66
            $tax->ID = -1;
67
        }
68
69
        return $tax;
70
    }
71
72
    /**
73
     * Get should this field automatically show the price including TAX?
74
     *
75
     * @return bool
76
     */
77
    public function getShowPriceWithTax()
78
    {
79
        return (bool)$this->config()->get('show_price_with_tax');
80
    }
81
82
    /**
83
     * Get if this field should add a "Tax String" (EG Includes VAT) to the rendered
84
     * currency?
85
     *
86
     * @return bool|null
87
     */
88
    public function getShowTaxString()
89
    {
90
        return (bool)$this->config()->get('show_tax_string');
91
    }
92
93
    /**
94
     * Return the currently available locale
95
     *
96
     * @return string
97
     */
98
    public function getLocale()
99
    {
100
        return i18n::get_locale();
101
    }
102
}
103