Completed
Push — master ( 6bfaa4...9a5e12 )
by Hannes
02:00
created

ItemEnvelope   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 87
ccs 21
cts 21
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTotalUnitCost() 0 4 1
A getTotalVatCost() 0 4 1
A getTotalCost() 0 4 1
A getCostPerUnit() 0 4 1
A getBillable() 0 4 1
A getCurrencyClassname() 0 4 1
A getBillingDescription() 0 4 1
A getNrOfUnits() 0 4 1
A getVatRate() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace byrokrat\billing;
6
7
use byrokrat\amount\Amount;
8
9
/**
10
 * Decorates a chargable billable with sum calculations
11
 */
12
class ItemEnvelope implements Billable
13
{
14
    /**
15
     * @var Billable
16
     */
17
    private $billable;
18
19
    /**
20
     * Pack billable at construct
21
     */
22 24
    public function __construct(Billable $billable)
23
    {
24 24
        $this->billable = $billable;
25 24
    }
26
27
    /**
28
     * Get packed billable
29
     */
30 24
    public function getBillable(): Billable
31
    {
32 24
        return $this->billable;
33
    }
34
35
    /**
36
     * Get total cost of all units (VAT excluded)
37
     */
38 14
    public function getTotalUnitCost(): Amount
39
    {
40 14
        return $this->getCostPerUnit()->multiplyWith($this->getNrOfUnits());
41
    }
42
43
    /**
44
     * Get total VAT cost for all units
45
     */
46 9
    public function getTotalVatCost(): Amount
47
    {
48 9
        return $this->getTotalUnitCost()->multiplyWith($this->getVatRate());
49
    }
50
51
    /**
52
     * Get total cost (VAT included)
53
     */
54 1
    public function getTotalCost(): Amount
55
    {
56 1
        return $this->getTotalUnitCost()->add($this->getTotalVatCost());
57
    }
58
59
    /**
60
     * Get classname of currency used in billable
61
     */
62 17
    public function getCurrencyClassname(): string
63
    {
64 17
        return get_class($this->getCostPerUnit());
65
    }
66
67
    /**
68
     * Pass to decorated billable
69
     */
70 1
    public function getBillingDescription(): string
71
    {
72 1
        return $this->getBillable()->getBillingDescription();
73
    }
74
75
    /**
76
     * Pass to decorated billable
77
     */
78 21
    public function getCostPerUnit(): Amount
79
    {
80 21
        return $this->getBillable()->getCostPerUnit();
81
    }
82
83
    /**
84
     * Pass to decorated billable
85
     */
86 17
    public function getNrOfUnits(): int
87
    {
88 17
        return $this->getBillable()->getNrOfUnits();
89
    }
90
91
    /**
92
     * Pass to decorated billable
93
     */
94 12
    public function getVatRate(): Amount
95
    {
96 12
        return $this->getBillable()->getVatRate();
97
    }
98
}
99