Passed
Push — main ( 41cc4d...b448d4 )
by Iain
04:36
created

Subscription::getStartOfCurrentPeriod()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 $mainExternalReferenceDetailsUrl = null;
43
44
    private string $childExternalReference;
45
46
    private string $paymentExternalReference;
47
48
    private ?SubscriptionPlan $subscriptionPlan = null;
49
50
    private ?Price $price = null;
51
52
    private \DateTimeInterface $createdAt;
53
54
    private ?\DateTimeInterface $startOfCurrentPeriod = null;
55
56
    private ?\DateTimeInterface $validUntil = null;
57
58
    private \DateTimeInterface $updatedAt;
59
60
    private ?\DateTimeInterface $endedAt = null;
61
62
    /**
63
     * @return mixed
64
     */
65
    public function getId()
66
    {
67
        return $this->id;
68
    }
69
70
    /**
71
     * @param mixed $id
72
     */
73
    public function setId($id): void
74
    {
75
        $this->id = $id;
76
    }
77
78
    public function getPlanName(): string
79
    {
80
        return $this->planName;
81
    }
82
83
    public function setPlanName(string $planName): void
84
    {
85
        $this->planName = $planName;
86
    }
87
88
    public function getPaymentSchedule(): string
89
    {
90
        return $this->paymentSchedule;
91
    }
92
93
    public function setPaymentSchedule(string $paymentSchedule): void
94
    {
95
        $this->paymentSchedule = $paymentSchedule;
96
    }
97
98
    public function getSeats(): ?int
99
    {
100
        return $this->seats;
101
    }
102
103
    public function setSeats(?int $seats): void
104
    {
105
        $this->seats = $seats;
106
    }
107
108
    public function getStatus(): string
109
    {
110
        return $this->status;
111
    }
112
113
    public function setStatus(string $status): void
114
    {
115
        $this->status = $status;
116
    }
117
118
    public function getSubscriptionPlan(): ?SubscriptionPlan
119
    {
120
        return $this->subscriptionPlan;
121
    }
122
123
    public function setSubscriptionPlan(?SubscriptionPlan $subscriptionPlan): void
124
    {
125
        $this->subscriptionPlan = $subscriptionPlan;
126
    }
127
128
    public function getMainExternalReference(): string
129
    {
130
        return $this->mainExternalReference;
131
    }
132
133
    public function setMainExternalReference(string $mainExternalReference): void
134
    {
135
        $this->mainExternalReference = $mainExternalReference;
136
    }
137
138
    public function getChildExternalReference(): string
139
    {
140
        return $this->childExternalReference;
141
    }
142
143
    public function setChildExternalReference(string $childExternalReference): void
144
    {
145
        $this->childExternalReference = $childExternalReference;
146
    }
147
148
    public function getAmount(): ?int
149
    {
150
        return $this->amount;
151
    }
152
153
    public function setAmount(?int $amount): void
154
    {
155
        $this->amount = $amount;
156
    }
157
158
    public function getCurrency(): ?string
159
    {
160
        return $this->currency;
161
    }
162
163
    public function setCurrency(?string $currency): void
164
    {
165
        $this->currency = $currency;
166
    }
167
168
    public function getPrice(): ?Price
169
    {
170
        return $this->price;
171
    }
172
173
    public function setPrice(?Price $price): void
174
    {
175
        $this->price = $price;
176
    }
177
178
    public function getCreatedAt(): \DateTimeInterface
179
    {
180
        return $this->createdAt;
181
    }
182
183
    public function setCreatedAt(\DateTimeInterface $createdAt): void
184
    {
185
        $this->createdAt = $createdAt;
186
    }
187
188
    public function getUpdatedAt(): \DateTimeInterface
189
    {
190
        return $this->updatedAt;
191
    }
192
193
    public function setUpdatedAt(\DateTimeInterface $updatedAt): void
194
    {
195
        $this->updatedAt = $updatedAt;
196
    }
197
198
    public function getEndedAt(): ?\DateTimeInterface
199
    {
200
        return $this->endedAt;
201
    }
202
203
    public function setEndedAt(?\DateTimeInterface $endedAt): void
204
    {
205
        $this->endedAt = $endedAt;
206
    }
207
208
    public function endAtEndOfPeriod(): void
209
    {
210
        $this->endedAt = clone $this->validUntil;
211
    }
212
213
    public function endNow(): void
214
    {
215
        $this->endedAt = new \DateTime('now');
216
        $this->validUntil = new \DateTime('now');
217
    }
218
219
    public function isActive(): bool
220
    {
221
        return $this->active;
222
    }
223
224
    public function setActive(bool $active): void
225
    {
226
        $this->active = $active;
227
    }
228
229
    public function getValidUntil(): \DateTimeInterface
230
    {
231
        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...
232
    }
233
234
    public function setValidUntil(\DateTimeInterface $validUntil): void
235
    {
236
        $this->validUntil = $validUntil;
237
    }
238
239
    public function getMoneyAmount(): Money
240
    {
241
        return Money::ofMinor($this->amount, Currency::of($this->currency));
242
    }
243
244
    public function setMoneyAmount(Money $money)
245
    {
246
        $this->amount = $money->getAmount()->getUnscaledValue()->toInt();
247
        $this->currency = $money->getCurrency()->getCurrencyCode();
248
    }
249
250
    public function getCustomer(): CustomerInterface
251
    {
252
        return $this->customer;
253
    }
254
255
    public function setCustomer(CustomerInterface $customer): void
256
    {
257
        $this->customer = $customer;
258
    }
259
260
    public function getMainExternalReferenceDetailsUrl(): ?string
261
    {
262
        return $this->mainExternalReferenceDetailsUrl;
263
    }
264
265
    public function setMainExternalReferenceDetailsUrl(?string $mainExternalReferenceDetailsUrl): void
266
    {
267
        $this->mainExternalReferenceDetailsUrl = $mainExternalReferenceDetailsUrl;
268
    }
269
270
    public function getPaymentExternalReference(): string
271
    {
272
        return $this->paymentExternalReference;
273
    }
274
275
    public function setPaymentExternalReference(?string $paymentExternalReference): void
276
    {
277
        $this->paymentExternalReference = $paymentExternalReference;
278
    }
279
280
    public function getStartOfCurrentPeriod(): ?\DateTimeInterface
281
    {
282
        return $this->startOfCurrentPeriod;
283
    }
284
285
    public function setStartOfCurrentPeriod(?\DateTimeInterface $startOfCurrentPeriod): void
286
    {
287
        $this->startOfCurrentPeriod = $startOfCurrentPeriod;
288
    }
289
}
290