This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * Copyright (C) 2020-2025 Iain Cambridge |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
||
10 | * the Free Software Foundation, either version 2.1 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Lesser General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | namespace Parthenon\Billing\Plan; |
||
23 | |||
24 | use Parthenon\Billing\Exception\NoPlanPriceFoundException; |
||
25 | use Parthenon\Common\Exception\ParameterNotSetException; |
||
26 | |||
27 | final class Plan implements PlanInterface |
||
28 | { |
||
29 | public const PAY_YEARLY = 'yearly'; |
||
30 | public const PAY_MONTHLY = 'monthly'; |
||
31 | public const CHECK_FEATURE = 'feature'; |
||
32 | |||
33 | public function __construct( |
||
34 | private string $name, |
||
35 | private array $limits, |
||
36 | private array $features, |
||
37 | private array $prices, |
||
38 | private bool $isFree, |
||
39 | private bool $isPerSeat, |
||
40 | private int $userCount, |
||
41 | private bool $public = false, |
||
42 | private ?bool $hasTrial = false, |
||
43 | private ?int $trialLengthDays = 0, |
||
44 | private mixed $entityId = null, |
||
45 | ) { |
||
46 | } |
||
47 | |||
48 | public function getName(): string |
||
49 | { |
||
50 | return $this->name; |
||
51 | } |
||
52 | |||
53 | public function hasFeature(string $featureName): bool |
||
54 | { |
||
55 | return in_array($featureName, $this->features); |
||
56 | } |
||
57 | |||
58 | public function getLimit(LimitableInterface $limitable): int |
||
59 | { |
||
60 | foreach ($this->limits as $name => $limit) { |
||
61 | if ($limitable->getLimitableName() === $name) { |
||
62 | if (!isset($limit['limit'])) { |
||
63 | throw new ParameterNotSetException('The limit is not set correctly'); |
||
64 | } |
||
65 | |||
66 | return $limit['limit']; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | return -1; |
||
71 | } |
||
72 | |||
73 | public function getLimits(): array |
||
74 | { |
||
75 | return $this->limits; |
||
76 | } |
||
77 | |||
78 | public function getPriceId(): ?string |
||
79 | { |
||
80 | return $this->priceId; |
||
81 | } |
||
82 | |||
83 | public function setPriceId(string $priceId): void |
||
84 | { |
||
85 | $this->priceId = $priceId; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @throws NoPlanPriceFoundException |
||
90 | */ |
||
91 | public function getPriceForPaymentSchedule(string $term, string $currency): PlanPrice |
||
92 | { |
||
93 | if (!isset($this->prices[$term][$currency])) { |
||
94 | throw new NoPlanPriceFoundException(sprintf("No currency '%s' found for '%s' schedule found", $currency, $term)); |
||
95 | } |
||
96 | |||
97 | return new PlanPrice($term, $this->prices[$term][$currency]['amount'], $currency, $this->prices[$term][$currency]['price_id'] ?? null, $this->prices[$term][$currency]['entity_id'] ?? null); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @return PlanPrice[] |
||
102 | */ |
||
103 | public function getPublicPrices(): array |
||
104 | { |
||
105 | $output = []; |
||
106 | foreach ($this->prices as $term => $currencyData) { |
||
107 | foreach ($currencyData as $currency => $data) { |
||
108 | if (!$data['public']) { |
||
109 | continue; |
||
110 | } |
||
111 | $output[] = new PlanPrice($term, $data['amount'], $currency, $data['price_id'] ?? null, $data['entity_id'] ?? null); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | return $output; |
||
116 | } |
||
117 | |||
118 | public function getFeatures(): array |
||
119 | { |
||
120 | return $this->features; |
||
121 | } |
||
122 | |||
123 | public function isFree(): bool |
||
124 | { |
||
125 | return $this->isFree; |
||
126 | } |
||
127 | |||
128 | public function isPerSeat(): bool |
||
129 | { |
||
130 | return $this->isPerSeat; |
||
131 | } |
||
132 | |||
133 | public function getUserCount(): int |
||
134 | { |
||
135 | return $this->userCount; |
||
136 | } |
||
137 | |||
138 | public function setPrices(array $prices): void |
||
139 | { |
||
140 | $this->prices = $prices; |
||
141 | } |
||
142 | |||
143 | public function isPublic(): bool |
||
144 | { |
||
145 | return $this->public; |
||
146 | } |
||
147 | |||
148 | public function getHasTrial(): bool |
||
149 | { |
||
150 | return true === $this->hasTrial; |
||
151 | } |
||
152 | |||
153 | public function setHasTrial(?bool $hasTrial): void |
||
154 | { |
||
155 | $this->hasTrial = $hasTrial; |
||
156 | } |
||
157 | |||
158 | public function getTrialLengthDays(): int |
||
159 | { |
||
160 | return (int) $this->trialLengthDays; |
||
161 | } |
||
162 | |||
163 | public function setTrialLengthDays(?int $trialLengthDays): void |
||
164 | { |
||
165 | $this->trialLengthDays = $trialLengthDays; |
||
166 | } |
||
167 | |||
168 | public function getEntityId(): mixed |
||
169 | { |
||
170 | return $this->entityId; |
||
171 | } |
||
172 | |||
173 | public function setEntityId(mixed $entityId): void |
||
174 | { |
||
175 | $this->entityId = $entityId; |
||
176 | } |
||
177 | |||
178 | public function hasEntityId(): bool |
||
179 | { |
||
180 | return isset($this->entityId); |
||
181 | } |
||
182 | } |
||
183 |