Passed
Push — main ( 09672f...0f2adf )
by Iain
04:20
created

Subscription::isMainSubscription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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
20
class Subscription
21
{
22
    private $id;
23
24
    private CustomerInterface $customer;
25
26
    private string $planName;
27
28
    private string $paymentSchedule;
29
30
    private ?int $seats = 1;
31
32
    private bool $active;
33
34
    private string $status;
35
36
    private ?int $amount = null;
37
38
    private ?string $currency = null;
39
40
    private string $mainExternalReference;
41
42
    private string $childExternalReference;
43
44
    private ?SubscriptionPlan $subscriptionPlan = null;
45
46
    private ?Price $price = null;
47
48
    private \DateTimeInterface $createdAt;
49
50
    private ?\DateTimeInterface $validUntil = null;
51
52
    private \DateTimeInterface $updatedAt;
53
54
    private ?\DateTimeInterface $endedAt = null;
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getId()
60
    {
61
        return $this->id;
62
    }
63
64
    /**
65
     * @param mixed $id
66
     */
67
    public function setId($id): void
68
    {
69
        $this->id = $id;
70
    }
71
72
    public function getPlanName(): string
73
    {
74
        return $this->planName;
75
    }
76
77
    public function setPlanName(string $planName): void
78
    {
79
        $this->planName = $planName;
80
    }
81
82
    public function getPaymentSchedule(): string
83
    {
84
        return $this->paymentSchedule;
85
    }
86
87
    public function setPaymentSchedule(string $paymentSchedule): void
88
    {
89
        $this->paymentSchedule = $paymentSchedule;
90
    }
91
92
    public function getSeats(): ?int
93
    {
94
        return $this->seats;
95
    }
96
97
    public function setSeats(?int $seats): void
98
    {
99
        $this->seats = $seats;
100
    }
101
102
    public function getStatus(): string
103
    {
104
        return $this->status;
105
    }
106
107
    public function setStatus(string $status): void
108
    {
109
        $this->status = $status;
110
    }
111
112
    public function getSubscriptionPlan(): ?SubscriptionPlan
113
    {
114
        return $this->subscriptionPlan;
115
    }
116
117
    public function setSubscriptionPlan(?SubscriptionPlan $subscriptionPlan): void
118
    {
119
        $this->subscriptionPlan = $subscriptionPlan;
120
    }
121
122
    public function getMainExternalReference(): string
123
    {
124
        return $this->mainExternalReference;
125
    }
126
127
    public function setMainExternalReference(string $mainExternalReference): void
128
    {
129
        $this->mainExternalReference = $mainExternalReference;
130
    }
131
132
    public function getChildExternalReference(): string
133
    {
134
        return $this->childExternalReference;
135
    }
136
137
    public function setChildExternalReference(string $childExternalReference): void
138
    {
139
        $this->childExternalReference = $childExternalReference;
140
    }
141
142
    public function getAmount(): ?int
143
    {
144
        return $this->amount;
145
    }
146
147
    public function setAmount(?int $amount): void
148
    {
149
        $this->amount = $amount;
150
    }
151
152
    public function getCurrency(): ?string
153
    {
154
        return $this->currency;
155
    }
156
157
    public function setCurrency(?string $currency): void
158
    {
159
        $this->currency = $currency;
160
    }
161
162
    public function getPrice(): ?Price
163
    {
164
        return $this->price;
165
    }
166
167
    public function setPrice(?Price $price): void
168
    {
169
        $this->price = $price;
170
    }
171
172
    public function getCreatedAt(): \DateTimeInterface
173
    {
174
        return $this->createdAt;
175
    }
176
177
    public function setCreatedAt(\DateTimeInterface $createdAt): void
178
    {
179
        $this->createdAt = $createdAt;
180
    }
181
182
    public function getUpdatedAt(): \DateTimeInterface
183
    {
184
        return $this->updatedAt;
185
    }
186
187
    public function setUpdatedAt(\DateTimeInterface $updatedAt): void
188
    {
189
        $this->updatedAt = $updatedAt;
190
    }
191
192
    public function getEndedAt(): ?\DateTimeInterface
193
    {
194
        return $this->endedAt;
195
    }
196
197
    public function setEndedAt(?\DateTimeInterface $endedAt): void
198
    {
199
        $this->endedAt = $endedAt;
200
    }
201
202
    public function isActive(): bool
203
    {
204
        return $this->active;
205
    }
206
207
    public function setActive(bool $active): void
208
    {
209
        $this->active = $active;
210
    }
211
212
    public function getValidUntil(): \DateTimeInterface
213
    {
214
        return $this->validUntil;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->validUntil could return the type null which is incompatible with the type-hinted return DateTimeInterface. Consider adding an additional type-check to rule them out.
Loading history...
215
    }
216
217
    public function setValidUntil(\DateTimeInterface $validUntil): void
218
    {
219
        $this->validUntil = $validUntil;
220
    }
221
222
    public function getMoneyAmount(): Money
223
    {
224
        return Money::ofMinor($this->amount, Currency::of($this->currency));
225
    }
226
227
    public function setMoneyAmount(Money $money)
228
    {
229
        $this->amount = $money->getAmount()->getUnscaledValue()->toInt();
230
        $this->currency = $money->getCurrency()->getCurrencyCode();
231
    }
232
233
    public function getCustomer(): CustomerInterface
234
    {
235
        return $this->customer;
236
    }
237
238
    public function setCustomer(CustomerInterface $customer): void
239
    {
240
        $this->customer = $customer;
241
    }
242
}
243