Passed
Push — main ( 0d1c63...8584cf )
by Iain
04:42
created

Subscription::getEndedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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