Passed
Push — main ( 061125...2568e0 )
by Iain
04:22
created

Price::isPublic()   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
use Parthenon\Athena\Entity\CrudEntityInterface;
20
use Parthenon\Athena\Entity\DeletableInterface;
21
22
class Price implements CrudEntityInterface, DeletableInterface
23
{
24
    protected ?string $paymentProviderDetailsUrl;
25
    private $id;
26
27
    private int $amount;
28
29
    private string $currency;
30
31
    private bool $recurring;
32
33
    private ?string $schedule = null;
34
35
    private ?string $externalReference = null;
36
37
    private bool $includingTax = true;
38
39
    private Product $product;
40
41
    private ?bool $public = true;
42
43
    private ?bool $deleted = false;
44
45
    private \DateTimeInterface $createdAt;
46
47
    private ?\DateTimeInterface $deletedAt = null;
48
49
    /**
50
     * @return mixed
51
     */
52
    public function getId()
53
    {
54
        return $this->id;
55
    }
56
57
    /**
58
     * @param mixed $id
59
     */
60
    public function setId($id): void
61
    {
62
        $this->id = $id;
63
    }
64
65
    public function getAmount(): int
66
    {
67
        return $this->amount;
68
    }
69
70
    public function setAmount(int $amount): void
71
    {
72
        $this->amount = $amount;
73
    }
74
75
    public function getCurrency(): string
76
    {
77
        return strtoupper($this->currency);
78
    }
79
80
    public function setCurrency(string $currency): void
81
    {
82
        $this->currency = $currency;
83
    }
84
85
    public function getExternalReference(): ?string
86
    {
87
        return $this->externalReference;
88
    }
89
90
    public function setExternalReference(?string $externalReference): void
91
    {
92
        $this->externalReference = $externalReference;
93
    }
94
95
    public function hasExternalReference(): bool
96
    {
97
        return isset($this->externalReference);
98
    }
99
100
    public function isRecurring(): bool
101
    {
102
        return $this->recurring;
103
    }
104
105
    public function setRecurring(bool $recurring): void
106
    {
107
        $this->recurring = $recurring;
108
    }
109
110
    public function getSchedule(): ?string
111
    {
112
        return $this->schedule;
113
    }
114
115
    public function setSchedule(?string $schedule): void
116
    {
117
        $this->schedule = $schedule;
118
    }
119
120
    public function isIncludingTax(): bool
121
    {
122
        return $this->includingTax;
123
    }
124
125
    public function setIncludingTax(bool $includingTax): void
126
    {
127
        $this->includingTax = $includingTax;
128
    }
129
130
    public function getAsMoney(): Money
131
    {
132
        return Money::ofMinor($this->amount, Currency::of($this->currency));
133
    }
134
135
    public function getProduct(): Product
136
    {
137
        return $this->product;
138
    }
139
140
    public function setProduct(Product $product): void
141
    {
142
        $this->product = $product;
143
    }
144
145
    public function isPublic(): bool
146
    {
147
        return true === $this->public;
148
    }
149
150
    public function setPublic(?bool $public): void
151
    {
152
        $this->public = $public;
153
    }
154
155
    public function getPaymentProviderDetailsUrl(): ?string
156
    {
157
        return $this->paymentProviderDetailsUrl;
158
    }
159
160
    public function setPaymentProviderDetailsUrl(?string $paymentProviderDetailsUrl): void
161
    {
162
        $this->paymentProviderDetailsUrl = $paymentProviderDetailsUrl;
163
    }
164
165
    public function getDisplayName(): string
166
    {
167
        if ($this->recurring) {
168
            $type = 'EmbeddedSubscription - '.$this->schedule;
169
        } else {
170
            $type = 'one-off';
171
        }
172
173
        return (string) $this->getAsMoney().' - '.$type.' - '.$this->getProduct()?->getName();
174
    }
175
176
    public function setDeletedAt(\DateTimeInterface $dateTime): DeletableInterface
177
    {
178
        $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...
179
    }
180
181
    public function isDeleted(): bool
182
    {
183
        return true === $this->deleted;
184
    }
185
186
    public function markAsDeleted(): DeletableInterface
187
    {
188
        $this->deletedAt = new \DateTime('now');
189
        $this->deleted = true;
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 unmarkAsDeleted(): DeletableInterface
193
    {
194
        $this->deletedAt = null;
195
        $this->deleted = false;
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...
196
    }
197
198
    public function getDeleted(): ?bool
199
    {
200
        return $this->deleted;
201
    }
202
203
    public function setDeleted(?bool $deleted): void
204
    {
205
        $this->deleted = $deleted;
206
    }
207
208
    public function getCreatedAt(): \DateTimeInterface
209
    {
210
        return $this->createdAt;
211
    }
212
213
    public function setCreatedAt(\DateTimeInterface $createdAt): void
214
    {
215
        $this->createdAt = $createdAt;
216
    }
217
}
218