BillableWithinTheEU   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 83
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setTaxForCountry() 0 7 1
A useTaxFrom() 0 6 1
A asBusiness() 0 6 1
A asIndividual() 0 6 1
A getTaxPercent() 0 4 1
A taxPercentage() 0 4 1
1
<?php
2
3
namespace Mpociot\VatCalculator\Traits;
4
5
use Mpociot\VatCalculator\Facades\VatCalculator;
6
7
trait BillableWithinTheEU
8
{
9
    /**
10
     * @var int
11
     */
12
    protected $stripeTaxPercent = 0;
13
14
    /**
15
     * @var
16
     */
17
    protected $userCountryCode;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $userIsCompany = false;
23
24
    /**
25
     * @param string     $countryCode
26
     * @param bool|false $company
27
     *
28
     * @return $this
29
     */
30
    public function setTaxForCountry($countryCode, $company = false)
31
    {
32
        $this->userCountryCode = $countryCode;
33
        $this->userIsCompany = $company;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param $countryCode
40
     *
41
     * @return $this
42
     */
43
    public function useTaxFrom($countryCode)
44
    {
45
        $this->userCountryCode = $countryCode;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return $this
52
     */
53
    public function asBusiness()
54
    {
55
        $this->userIsCompany = true;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return $this
62
     */
63
    public function asIndividual()
64
    {
65
        $this->userIsCompany = false;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Get the tax percentage to apply to the subscription.
72
     *
73
     * @return int
74
     */
75
    public function getTaxPercent()
76
    {
77
        return VatCalculator::getTaxRateForCountry($this->userCountryCode, $this->userIsCompany) * 100;
78
    }
79
80
    /**
81
     * Get the tax percentage to apply to the subscription for Cashier > 6.0.
82
     *
83
     * @return int
84
     */
85
    public function taxPercentage()
86
    {
87
        return $this->getTaxPercent();
88
    }
89
}
90