Completed
Push — master ( b48562...7495d6 )
by Jorge
05:44 queued 04:26
created

Tax   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 73
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A percentage() 0 13 1
A getTaxName() 0 6 1
A parseTypePercentage() 0 4 2
A __get() 0 8 2
A __toString() 0 4 1
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(
0 ignored issues
show
Unused Code introduced by
$percentage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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