Passed
Push — main ( 32df9e...69c2a6 )
by Iain
04:47
created

Price::getDisplayName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Entity;
16
17
use Brick\Money\Currency;
18
use Brick\Money\Money;
19
use Parthenon\Athena\Entity\CrudEntityInterface;
20
21
class Price implements CrudEntityInterface
22
{
23
    private $id;
24
25
    private int $amount;
26
27
    private string $currency;
28
29
    private bool $recurring;
30
31
    private ?string $schedule = null;
32
33
    private ?string $externalReference = null;
34
35
    private bool $includingTax = true;
36
37
    private Product $product;
38
39
    /**
40
     * @return mixed
41
     */
42
    public function getId()
43
    {
44
        return $this->id;
45
    }
46
47
    /**
48
     * @param mixed $id
49
     */
50
    public function setId($id): void
51
    {
52
        $this->id = $id;
53
    }
54
55
    public function getAmount(): int
56
    {
57
        return $this->amount;
58
    }
59
60
    public function setAmount(int $amount): void
61
    {
62
        $this->amount = $amount;
63
    }
64
65
    public function getCurrency(): string
66
    {
67
        return $this->currency;
68
    }
69
70
    public function setCurrency(string $currency): void
71
    {
72
        $this->currency = $currency;
73
    }
74
75
    public function getExternalReference(): ?string
76
    {
77
        return $this->externalReference;
78
    }
79
80
    public function setExternalReference(?string $externalReference): void
81
    {
82
        $this->externalReference = $externalReference;
83
    }
84
85
    public function hasExternalReference(): bool
86
    {
87
        return isset($this->externalReference);
88
    }
89
90
    public function isRecurring(): bool
91
    {
92
        return $this->recurring;
93
    }
94
95
    public function setRecurring(bool $recurring): void
96
    {
97
        $this->recurring = $recurring;
98
    }
99
100
    public function getSchedule(): ?string
101
    {
102
        return $this->schedule;
103
    }
104
105
    public function setSchedule(?string $schedule): void
106
    {
107
        $this->schedule = $schedule;
108
    }
109
110
    public function isIncludingTax(): bool
111
    {
112
        return $this->includingTax;
113
    }
114
115
    public function setIncludingTax(bool $includingTax): void
116
    {
117
        $this->includingTax = $includingTax;
118
    }
119
120
    public function getAsMoney(): Money
121
    {
122
        return Money::ofMinor($this->amount, Currency::of($this->currency));
123
    }
124
125
    public function getProduct(): Product
126
    {
127
        return $this->product;
128
    }
129
130
    public function setProduct(Product $product): void
131
    {
132
        $this->product = $product;
133
    }
134
135
    public function getDisplayName(): string
136
    {
137
        if ($this->recurring) {
138
            $type = 'Subscription - '.$this->schedule;
139
        } else {
140
            $type = 'one-off';
141
        }
142
143
        return (string) $this->getAsMoney().' - '.$type.' - '.$this->getProduct()?->getName();
144
    }
145
}
146