BillContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setAmount() 0 4 1
A getStructure() 0 3 1
A __construct() 0 4 1
A getAmount() 0 3 1
A setStructure() 0 4 1
1
<?php
2
declare(strict_types=1);
3
namespace BillingBoss;
4
5
/**
6
 * Class BillContext
7
 *
8
 * @category BillingBoss
9
 * @package  BillingBoss
10
 * @author   Ransford Okpoti <[email protected]>
11
 * @license  https://opensource.org/licenses/MIT MIT
12
 * @link     https://github.com/ranskills/billing-boss-php
13
 * @since    1.0.0
14
 */
15
final class BillContext
16
{
17
    private $amount;
18
    private $structure;
19
20
    /**
21
     * Constructor
22
     *
23
     * @param float  $amount    The amount to be billed
24
     * @param string $structure The billing structure to be applied on $amount
25
     */
26
    public function __construct(float $amount, string $structure)
27
    {
28
        $this->amount = $amount;
29
        $this->setStructure($structure);
30
    }
31
32
    /**
33
     * Returns the amount
34
     *
35
     * @return float
36
     */
37
    public function getAmount(): float
38
    {
39
        return $this->amount;
40
    }
41
42
    /**
43
     * Sets the amount and returns this instance
44
     *
45
     * @param float $amount The amount to be billed
46
     *
47
     * @return BillContext
48
     */
49
    public function setAmount(float $amount)
50
    {
51
        $this->amount = $amount;
52
        return $this;
53
    }
54
55
    /**
56
     * Returns the structure for this context
57
     *
58
     * @return string
59
     */
60
    public function getStructure(): string
61
    {
62
        return $this->structure;
63
    }
64
65
    /**
66
     * Sets the billing structure for the context
67
     *
68
     * @param string $structure The billing structure
69
     *
70
     * @return BillContext
71
     */
72
    public function setStructure(string $structure)
73
    {
74
        $this->structure = trim(preg_replace('/\s+/', ' ', $structure));
75
        return $this;
76
    }
77
}
78