|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FeiMx\Tax\Taxes; |
|
4
|
|
|
|
|
5
|
|
|
class Tax |
|
6
|
|
|
{ |
|
7
|
|
|
protected $retention = false; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Create new instance of taxes. |
|
11
|
|
|
* |
|
12
|
|
|
* @param bool $retention |
|
13
|
|
|
*/ |
|
14
|
|
|
public function __construct(bool $retention = false) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->retention = $retention; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Get amount percentage for defined tax. |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $type Type of the tax amount |
|
23
|
|
|
* |
|
24
|
|
|
* @return int $percentage Amount of the tax |
|
25
|
|
|
*/ |
|
26
|
|
|
public function percentage($type = 'default'): float |
|
27
|
|
|
{ |
|
28
|
|
|
$taxName = $this->getTaxName(); |
|
29
|
|
|
|
|
30
|
|
|
$type = $this->parseTypePercentage($type); |
|
31
|
|
|
|
|
32
|
|
|
return $percentage = config( |
|
|
|
|
|
|
33
|
|
|
"tax.taxes.{$taxName}.{$type}", |
|
34
|
|
|
config( |
|
35
|
|
|
"tax.taxes.{$taxName}.".config('tax.fallback') |
|
36
|
|
|
) |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Convert class to qualified Tax name. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string Tax name in lower case |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getTaxName(): string |
|
46
|
|
|
{ |
|
47
|
|
|
$className = explode('\\', get_called_class()); |
|
48
|
|
|
|
|
49
|
|
|
return strtolower(array_pop($className)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Return retention instead of a given type if retention flag is activated. |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $type Type of the tax amount |
|
56
|
|
|
* |
|
57
|
|
|
* @return string Type of the tax amount |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function parseTypePercentage($type = 'default') |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->retention ? 'retention' : $type; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function __get($property) |
|
65
|
|
|
{ |
|
66
|
|
|
if ('name' == $property) { |
|
67
|
|
|
return $this->getTaxName(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
throw new \Exception('Property not exists'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function __toString() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->getTaxName(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.