Completed
Push — master ( 308de5...6bfaa4 )
by Hannes
03:47 queued 02:10
created

ItemEnvelope::getDescription()   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 15
    public function __construct(Billable $billable)
23
    {
24 15
        $this->billable = $billable;
25 15
    }
26
27
    /**
28
     * Get packed billable
29
     */
30 13
    public function getBillable(): Billable
31
    {
32 13
        return $this->billable;
33
    }
34
35
    /**
36
     * Get total cost of all units (VAT excluded)
37
     */
38 8
    public function getTotalUnitCost(): Amount
39
    {
40 8
        return $this->getCostPerUnit()->multiplyWith($this->getNrOfUnits());
41
    }
42
43
    /**
44
     * Get total VAT cost for all units
45
     */
46 5
    public function getTotalVatCost(): Amount
47
    {
48 5
        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
     * Pass to decorated billable
61
     */
62 1
    public function getBillingDescription(): string
63
    {
64 1
        return $this->getBillable()->getBillingDescription();
65
    }
66
67
    /**
68
     * Pass to decorated billable
69
     */
70 9
    public function getCostPerUnit(): Amount
71
    {
72 9
        return $this->getBillable()->getCostPerUnit();
73
    }
74
75
    /**
76
     * Pass to decorated billable
77
     */
78 10
    public function getNrOfUnits(): int
79
    {
80 10
        return $this->getBillable()->getNrOfUnits();
81
    }
82
83
    /**
84
     * Pass to decorated billable
85
     */
86 7
    public function getVatRate(): Amount
87
    {
88 7
        return $this->getBillable()->getVatRate();
89
    }
90
}
91