Passed
Push — main ( 01abec...3df85b )
by Iain
16:41
created

SubscriptionPlan::getPriceForCurrencyAndSchedule()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Software Limited 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: 26.06.2026 ( 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 Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use Parthenon\Athena\Entity\CrudEntityInterface;
20
21
class SubscriptionPlan implements CrudEntityInterface
22
{
23
    private $id;
24
25
    private bool $public = false;
26
27
    private string $name;
28
29
    private ?string $codeName = null;
30
31
    private ?string $externalReference = null;
32
33
    private ?string $paymentProviderDetailsLink = null;
34
35
    private array|Collection $limits;
36
37
    private bool $perSeat;
38
39
    private bool $free;
40
41
    private int $userCount;
42
43
    private ?bool $hasTrial = false;
44
45
    private ?int $trialLengthDays = 0;
46
47
    private array|Collection $features;
48
49
    private array|Collection $prices;
50
51
    private Product $product;
52
53
    public function __construct()
54
    {
55
        $this->limits = new ArrayCollection();
56
        $this->features = new ArrayCollection();
57
        $this->prices = new ArrayCollection();
58
    }
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 isPublic(): bool
77
    {
78
        return $this->public;
79
    }
80
81
    public function setPublic(bool $public): void
82
    {
83
        $this->public = $public;
84
    }
85
86
    public function getName(): string
87
    {
88
        return $this->name;
89
    }
90
91
    public function setName(string $name): void
92
    {
93
        $this->name = $name;
94
    }
95
96
    public function getCodeName(): ?string
97
    {
98
        return $this->codeName;
99
    }
100
101
    public function setCodeName(?string $codeName): void
102
    {
103
        $this->codeName = $codeName;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getExternalReference(): ?string
110
    {
111
        return $this->externalReference;
112
    }
113
114
    public function setExternalReference(string $externalReference): void
115
    {
116
        $this->externalReference = $externalReference;
117
    }
118
119
    public function hasExternalReference(): bool
120
    {
121
        return isset($this->externalReference);
122
    }
123
124
    public function getPaymentProviderDetailsLink(): ?string
125
    {
126
        return $this->paymentProviderDetailsLink;
127
    }
128
129
    public function setPaymentProviderDetailsLink(?string $paymentProviderDetailsLink): void
130
    {
131
        $this->paymentProviderDetailsLink = $paymentProviderDetailsLink;
132
    }
133
134
    public function getLimits(): Collection|array
135
    {
136
        return $this->limits;
137
    }
138
139
    /**
140
     * @param SubscriptionPlanLimit[]|Collection $limits
141
     */
142
    public function setLimits(Collection|array $limits): void
143
    {
144
        $this->limits = $limits;
145
    }
146
147
    public function addLimit(SubscriptionPlanLimit $limit): void
148
    {
149
        if (!$this->limits->contains($limit)) {
150
            $limit->setSubscriptionPlan($this);
151
            $this->limits->add($limit);
152
        }
153
    }
154
155
    public function removeLimit(SubscriptionPlanLimit $limit): void
156
    {
157
        $this->limits->removeElement($limit);
158
    }
159
160
    public function addFeature(SubscriptionFeature $subscriptionFeature): void
161
    {
162
        if (!$this->features->contains($subscriptionFeature)) {
163
            $this->features->add($subscriptionFeature);
164
        }
165
    }
166
167
    public function removeFeature(SubscriptionFeature $subscriptionFeature): void
168
    {
169
        $this->features->removeElement($subscriptionFeature);
170
    }
171
172
    public function addPrice(Price $price): void
173
    {
174
        if (!$this->prices->contains($price)) {
175
            $this->prices->add($price);
176
        }
177
    }
178
179
    public function getPriceForCurrencyAndSchedule(string $currency, string $schedule): Price
180
    {
181
        foreach ($this->getPrices() as $price) {
182
            if (strtolower($price->getCurrency()) === strtolower($currency) && strtolower($price->getSchedule()) === strtolower($schedule)) {
183
                return $price;
184
            }
185
        }
186
        throw new \Exception("Can't found price");
187
    }
188
189
    public function removePrice(Price $price): void
190
    {
191
        $this->prices->removeElement($price);
192
    }
193
194
    public function getPrices(): Collection|array
195
    {
196
        return $this->prices;
197
    }
198
199
    public function setPrices(Collection|array $prices): void
200
    {
201
        $this->prices = $prices;
202
    }
203
204
    public function getDisplayName(): string
205
    {
206
        return $this->name;
207
    }
208
209
    public function isPerSeat(): bool
210
    {
211
        return $this->perSeat;
212
    }
213
214
    public function setPerSeat(bool $perSeat): void
215
    {
216
        $this->perSeat = $perSeat;
217
    }
218
219
    public function isFree(): bool
220
    {
221
        return $this->free;
222
    }
223
224
    public function setFree(bool $free): void
225
    {
226
        $this->free = $free;
227
    }
228
229
    public function getUserCount(): int
230
    {
231
        return $this->userCount;
232
    }
233
234
    public function setUserCount(int $userCount): void
235
    {
236
        $this->userCount = $userCount;
237
    }
238
239
    public function getFeatures(): Collection|array
240
    {
241
        return $this->features;
242
    }
243
244
    public function setFeatures(Collection|array $features): void
245
    {
246
        $this->features = $features;
247
    }
248
249
    public function getProduct(): Product
250
    {
251
        return $this->product;
252
    }
253
254
    public function setProduct(Product $product): void
255
    {
256
        $this->product = $product;
257
    }
258
259
    public function getHasTrial(): bool
260
    {
261
        return true === $this->hasTrial;
262
    }
263
264
    public function setHasTrial(?bool $hasTrial): void
265
    {
266
        $this->hasTrial = $hasTrial;
267
    }
268
269
    public function getTrialLengthDays(): int
270
    {
271
        return (int) $this->trialLengthDays;
272
    }
273
274
    public function setTrialLengthDays(?int $trialLengthDays): void
275
    {
276
        $this->trialLengthDays = $trialLengthDays;
277
    }
278
}
279