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

ItemEnvelope   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 79
wmc 9
lcom 1
cbo 2
ccs 19
cts 19
cp 1
rs 10

9 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 getVatRate() 0 4 1
A getBillable() 0 4 1
A getBillingDescription() 0 4 1
A getCostPerUnit() 0 4 1
A getNrOfUnits() 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 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