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

SimpleItem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 55
wmc 6
lcom 0
cbo 1
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getBillingDescription() 0 4 1
A getCostPerUnit() 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
 * Basic billable implementation
11
 */
12
class SimpleItem implements Billable
13
{
14
    /**
15
     * @var string
16
     */
17
    private $description;
18
19
    /**
20
     * @var Amount
21
     */
22
    private $unitCost;
23
24
    /**
25
     * @var int
26
     */
27
    private $units;
28
29
    /**
30
     * @var Amount
31
     */
32
    private $vat;
33
34
    /**
35
     * Set immutable data at construct
36
     *
37
     * Note that a VAT of 25% is represented as .25
38
     */
39 5
    public function __construct(string $description, Amount $unitCost, int $units = 1, Amount $vat = null)
40
    {
41 5
        $this->description = $description;
42 5
        $this->unitCost = $unitCost;
43 5
        $this->units = $units;
44 5
        $this->vat = $vat ?: new Amount('.25');
45 5
    }
46
47 2
    public function getBillingDescription(): string
48
    {
49 2
        return $this->description;
50
    }
51
52 2
    public function getCostPerUnit(): Amount
53
    {
54 2
        return $this->unitCost;
55
    }
56
57 2
    public function getNrOfUnits(): int
58
    {
59 2
        return $this->units;
60
    }
61
62 2
    public function getVatRate(): Amount
63
    {
64 2
        return $this->vat;
65
    }
66
}
67