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

ItemEnvelope::getCurrencyClassname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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