Passed
Push — main ( 8887d0...3fb85e )
by Iain
18:40
created

Price::setUsageType()   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 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2024 Iain Cambridge
7
 *
8
 *     This program is free software: you can redistribute it and/or modify
9
 *     it under the terms of the GNU General Public License as published by
10
 *     the Free Software Foundation, either version 3 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 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\Entity;
23
24
use Brick\Money\Currency;
25
use Brick\Money\Money;
26
use Doctrine\Common\Collections\Collection;
27
use Parthenon\Athena\Entity\CrudEntityInterface;
28
use Parthenon\Athena\Entity\DeletableInterface;
29
use Parthenon\Billing\Enum\PriceType;
30
use Parthenon\Billing\Enum\UsageType;
31
32
class Price implements CrudEntityInterface, DeletableInterface, PriceInterface
33
{
34
    protected $id;
35
36
    protected int $amount;
37
38
    protected string $currency;
39
40
    protected bool $recurring;
41
42
    protected ?string $schedule = null;
43
44
    protected ?string $externalReference = null;
45
46
    protected bool $includingTax = true;
47
48
    protected Product $product;
49
50
    protected ?bool $public = true;
51
52
    protected ?bool $isDeleted = false;
53
54
    protected \DateTimeInterface $createdAt;
55
56
    protected ?\DateTimeInterface $deletedAt = null;
57
58
    protected ?string $paymentProviderDetailsUrl = null;
59
60
    protected array|Collection $tierComponents = [];
61
62
    protected PriceType $type;
63
64
    protected ?UsageType $usageType = null;
65
66
    public function getId()
67
    {
68
        return $this->id;
69
    }
70
71
    public function setId($id): void
72
    {
73
        $this->id = $id;
74
    }
75
76
    public function getAmount(): int
77
    {
78
        return $this->amount;
79
    }
80
81
    public function setAmount(int $amount): void
82
    {
83
        $this->amount = $amount;
84
    }
85
86
    public function getCurrency(): string
87
    {
88
        return strtoupper($this->currency);
89
    }
90
91
    public function setCurrency(string $currency): void
92
    {
93
        $this->currency = $currency;
94
    }
95
96
    public function getExternalReference(): ?string
97
    {
98
        return $this->externalReference;
99
    }
100
101
    public function setExternalReference(?string $externalReference): void
102
    {
103
        $this->externalReference = $externalReference;
104
    }
105
106
    public function hasExternalReference(): bool
107
    {
108
        return isset($this->externalReference);
109
    }
110
111
    public function isRecurring(): bool
112
    {
113
        return $this->recurring;
114
    }
115
116
    public function setRecurring(bool $recurring): void
117
    {
118
        $this->recurring = $recurring;
119
    }
120
121
    public function getSchedule(): ?string
122
    {
123
        return $this->schedule;
124
    }
125
126
    public function setSchedule(?string $schedule): void
127
    {
128
        $this->schedule = $schedule;
129
    }
130
131
    public function isIncludingTax(): bool
132
    {
133
        return $this->includingTax;
134
    }
135
136
    public function setIncludingTax(bool $includingTax): void
137
    {
138
        $this->includingTax = $includingTax;
139
    }
140
141
    public function getAsMoney(): Money
142
    {
143
        return Money::ofMinor($this->amount, Currency::of($this->currency));
144
    }
145
146
    public function getProduct(): Product
147
    {
148
        return $this->product;
149
    }
150
151
    public function setProduct(Product $product): void
152
    {
153
        $this->product = $product;
154
    }
155
156
    public function isPublic(): bool
157
    {
158
        return true === $this->public;
159
    }
160
161
    public function setPublic(?bool $public): void
162
    {
163
        $this->public = $public;
164
    }
165
166
    public function getPaymentProviderDetailsUrl(): ?string
167
    {
168
        return $this->paymentProviderDetailsUrl;
169
    }
170
171
    public function setPaymentProviderDetailsUrl(?string $paymentProviderDetailsUrl): void
172
    {
173
        $this->paymentProviderDetailsUrl = $paymentProviderDetailsUrl;
174
    }
175
176
    public function getDisplayName(): string
177
    {
178
        if ($this->recurring) {
179
            $type = 'EmbeddedSubscription - '.$this->schedule;
180
        } else {
181
            $type = 'one-off';
182
        }
183
184
        return (string) $this->getAsMoney().' - '.$type.' - '.$this->getProduct()?->getName();
185
    }
186
187
    public function setDeletedAt(\DateTimeInterface $dateTime): DeletableInterface
188
    {
189
        $this->deletedAt = $dateTime;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Parthenon\Athena\Entity\DeletableInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
190
    }
191
192
    public function isDeleted(): bool
193
    {
194
        return true === $this->isDeleted;
195
    }
196
197
    public function markAsDeleted(): DeletableInterface
198
    {
199
        $this->deletedAt = new \DateTime('now');
200
        $this->isDeleted = true;
201
202
        return $this;
203
    }
204
205
    public function unmarkAsDeleted(): DeletableInterface
206
    {
207
        $this->deletedAt = null;
208
        $this->isDeleted = false;
209
210
        return $this;
211
    }
212
213
    public function getIsDeleted(): ?bool
214
    {
215
        return $this->isDeleted;
216
    }
217
218
    public function setIsDeleted(?bool $isDeleted): void
219
    {
220
        $this->isDeleted = $isDeleted;
221
    }
222
223
    public function getCreatedAt(): \DateTimeInterface
224
    {
225
        return $this->createdAt;
226
    }
227
228
    public function setCreatedAt(\DateTimeInterface $createdAt): void
229
    {
230
        $this->createdAt = $createdAt;
231
    }
232
233
    public function getTierComponents(): Collection|array
234
    {
235
        return $this->tierComponents;
236
    }
237
238
    public function setTierComponents(Collection|array $tierComponents): void
239
    {
240
        $this->tierComponents = $tierComponents;
241
    }
242
243
    public function getType(): PriceType
244
    {
245
        return $this->type;
246
    }
247
248
    public function setType(PriceType $type): void
249
    {
250
        $this->type = $type;
251
    }
252
253
    public function getUsageType(): ?UsageType
254
    {
255
        return $this->usageType;
256
    }
257
258
    public function setUsageType(?UsageType $usageType): void
259
    {
260
        $this->usageType = $usageType;
261
    }
262
}
263