Test Setup Failed
Push — master ( 4c62c0...259020 )
by Bruce Pinheiro de
02:12
created

Checkout::setType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace BPCI\SumUp\Checkout;
3
4
use BPCI\SumUp\ContextInterface;
5
use BPCI\SumUp\Customer\Card\Card;
6
use BPCI\SumUp\Customer\Customer;
7
use BPCI\SumUp\Exception\BadRequestException;
8
use BPCI\SumUp\Exception\InvalidCheckoutException;
9
use BPCI\SumUp\OAuth\AccessToken;
10
use BPCI\SumUp\OAuth\AuthenticationHelper;
11
use BPCI\SumUp\SumUp;
12
use BPCI\SumUp\Customer\CustomerInterface;
13
use BPCI\SumUp\Customer\Card\CardInterface;
14
use BPCI\SumUp\Traits\PropertyHandler;
15
use BPCI\SumUp\Utils\Currency;
16
use BPCI\SumUp\Utils\Hydrator;
0 ignored issues
show
Bug introduced by
The type BPCI\SumUp\Utils\Hydrator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 */
20
class Checkout implements CheckoutInterface
21
{
22
	use PropertyHandler;
23
24
	const PENDING = 'PENDING';
25
	const COMPLETED = 'COMPLETED';
26
	const FAILED = 'FAILED';
27
28
	protected $id;
29
	protected $status;
30
	protected $amount;
31
	protected $feeAmount;
32
	protected $currency;
33
	protected $payToEmail;
34
	protected $payFromEmail;
35
	protected $description;
36
	protected $redirectUrl;
37
	protected $validUntil;
38
	protected $token;
39
	protected $transactionId;
40
	protected $transactionCode;
41
	protected $type;
42
	protected $installments;
43
44
	/**
45
	 * Checkout reference
46
	 *
47
	 * @var string
48
	 */
49
	protected $reference;
50
51
	/**
52
	 * Customer
53
	 *
54
	 * @var null|Customer
55
	 */
56
	protected $customer;
57
58
	/**
59
	 * Card
60
	 *
61
	 *
62
	 * @var null|Card
63
	 */
64
	protected $card;
65
66
67
	/**
68
	 * checkout constructor
69
	 *
70
	 * @param array $data
71
	 */
72
	public function __construct(array $data = null) {
73
		if ($data !== null) {
74
			$this->setAmount($data['amount']??null);
0 ignored issues
show
Bug introduced by
It seems like $data['amount'] ?? null can also be of type null; however, parameter $amount of BPCI\SumUp\Checkout\Checkout::setAmount() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
			$this->setAmount(/** @scrutinizer ignore-type */ $data['amount']??null);
Loading history...
75
			$this->setPayToEmail($data['pay_to_email']??null);
0 ignored issues
show
Bug introduced by
It seems like $data['pay_to_email'] ?? null can also be of type null; however, parameter $email of BPCI\SumUp\Checkout\Checkout::setPayToEmail() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
			$this->setPayToEmail(/** @scrutinizer ignore-type */ $data['pay_to_email']??null);
Loading history...
76
			$this->setCheckoutReference($data['checkout_reference']??null);
0 ignored issues
show
Bug introduced by
It seems like $data['checkout_reference'] ?? null can also be of type null; however, parameter $reference of BPCI\SumUp\Checkout\Chec...:setCheckoutReference() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
			$this->setCheckoutReference(/** @scrutinizer ignore-type */ $data['checkout_reference']??null);
Loading history...
77
			$this->setCurrency($data['currency']??null);
78
			$this->setDescription($data['description']??null);
79
			$this->setFeeAmount($data['fee_amount']??null);
80
			$this->setPayFromEmail($data['pay_from_mail']??null);
81
			$this->setId($data['id']??null);
82
			$this->setRedirectUrl($data['redirect_url']??null);
83
			$this->setStatus($data['status']??null);
84
		}
85
	}
86
87
	/**
88
	 * @inheritDoc
89
	 */
90
	public function isValid(): bool {
91
		return $this->getReference() !== null
92
			&& $this->getAmount() !== null
93
			&& $this->getPayToEmail() !== null
94
			&& Currency::isValid($this->getCurrency());
95
	}
96
97
	/**
98
	 * @inheritDoc
99
	 */
100
	public function getId():? string {
101
		return $this->id;
102
	}
103
104
	/**
105
	 * @inheritDoc
106
	 */
107
	public function setId(?string $id): CheckoutInterface {
108
		$this->id = $id;
109
		return $this;
110
	}
111
112
	/**
113
	 * @inheritDoc
114
	 */
115
	public function getStatus():? string {
116
		return $this->status;
117
	}
118
119
	/**
120
	 * @inheritDoc
121
	 */
122
	public function setStatus(?string $status): CheckoutInterface {
123
		$this->status = $status;
124
		return $this;
125
	}
126
127
	/**
128
	 * @inheritDoc
129
	 */
130
	public function getAmount():? float {
131
		return $this->amount;
132
	}
133
134
	/**
135
	 * @inheritDoc
136
	 */
137
	public function setAmount(float $amount): CheckoutInterface {
138
		$this->amount = $amount > 0 ? $amount : null;
139
		return $this;
140
	}
141
142
	/**
143
	 * @inheritDoc
144
	 */
145
	public function getCurrency():? string {
146
		return $this->currency;
147
	}
148
149
	/**
150
	 * @inheritDoc
151
	 */
152
	public function setCurrency(?string $currency): CheckoutInterface {
153
		$this->currency = $currency;
154
		return $this;
155
	}
156
157
	/**
158
	 * @inheritDoc
159
	 */
160
	public function getPayToEmail():? string {
161
		return $this->payToEmail;
162
	}
163
164
	/**
165
	 * @inheritDoc
166
	 */
167
	public function setPayToEmail(string $email): CheckoutInterface {
168
		$this->payToEmail = trim($email) === '' ? null : $email;
169
		return $this;
170
	}
171
172
	/**
173
	 * @inheritDoc
174
	 */
175
	public function getCheckoutReference():? string {
176
		return $this->reference;
177
	}
178
179
	/**
180
	 * @inheritDoc
181
	 */
182
	public function setCheckoutReference(string $reference): CheckoutInterface {
183
		$this->reference = trim($reference) === '' ? null : $reference;
184
		return $this;
185
	}
186
187
	/**
188
	 * @inheritDoc
189
	 */
190
	public function getDescription():? string {
191
		return $this->description;
192
	}
193
194
	/**
195
	 * @inheritDoc
196
	 */
197
	public function setDescription(?string $description): CheckoutInterface {
198
		$this->description = $description;
199
		return $this;
200
	}
201
202
	/**
203
	 * @inheritDoc
204
	 */
205
	public function getFeeAmount():? float {
206
		return $this->feeAmount;
207
	}
208
209
	/**
210
	 * @inheritDoc
211
	 */
212
	public function setFeeAmount(?float $fee): CheckoutInterface {
213
		$this->feeAmount = $fee;
214
		return $this;
215
	}
216
217
	/**
218
	 * @inheritDoc
219
	 */
220
	public function getPayFromEmail():? string {
221
		return $this->payFromEmail;
222
	}
223
224
	/**
225
	 * @inheritDoc
226
	 */
227
	public function setPayFromEmail(?string $email): CheckoutInterface {
228
		$this->payFromEmail = $email;
229
		return $this;
230
	}
231
232
	/**
233
	 * @inheritDoc
234
	 */
235
	public function getRedirectUrl():? string {
236
		return $this->redirectUrl;
237
	}
238
239
	/**
240
	 * @inheritDoc
241
	 */
242
	public function setRedirectUrl(?string $url): CheckoutInterface {
243
		$this->redirectUrl = $url;
244
		return $this;
245
	}
246
247
	function getValidUntil():? string {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
248
		return $this->validUntil;
249
	}
250
251
	function setValidUntil(?string $timestamp): CheckoutInterface {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
252
		$this->validUntil = $timestamp;
253
		return $this;
254
	}
255
256
	function getTransactionCode():? string {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
257
		return $this->transactionCode;
258
	}
259
260
	function setTransactionCode(?string $code): CheckoutInterface {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
261
		$this->transactionCode = $code;
262
		return $this;
263
	}
264
265
	function getTransactionId():? string {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
266
		return $this->transactionId;
267
	}
268
269
	function setTransactionId(?string $id): CheckoutInterface {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
270
		$this->transactionId = $id;
271
		return $this;
272
	}
273
274
	function getTransactions():? array {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
275
//        return $this->transactions;
276
		//TODO remember myself whats is it.
277
		return [];
278
	}
279
280
	function setTransactions(?Array $transactions): CheckoutInterface {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
281
//        $this->transactions = $transactions;
282
		//TODO remember myself whats is it.
283
		return $this;
284
	}
285
286
	function getToken():? string {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
287
		return $this->token;
288
	}
289
290
	function setToken(?string $token): CheckoutInterface {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
291
		$this->token = $token;
292
		return $this;
293
	}
294
295
	/**
296
	 * Get customer
297
	 * @return CustomerInterface|null
298
	 */
299
	public function getCustomer(): ?CustomerInterface
300
	{
301
		return $this->customer;
302
	}
303
304
	/**
305
	 * Set customer
306
	 *
307
	 * @param  null|CustomerInterface  $customer  Customer
308
	 *
309
	 * @return  CheckoutInterface
310
	 */
311
	public function setCustomer(?CustomerInterface $customer): CheckoutInterface
312
	{
313
		$this->customer = $customer;
314
315
		return $this;
316
	}
317
318
	/**
319
	 * Get card
320
	 *
321
	 * @return  null|CardInterface
322
	 */
323
	public function getCard(): ?CardInterface
324
	{
325
		return $this->card;
326
	}
327
328
	/**
329
	 * Set card
330
	 *
331
	 * @param  null|CardInterface  $card
332
	 *
333
	 * @return  CheckoutInterface
334
	 */
335
	public function setCard(?CardInterface $card): CheckoutInterface
336
	{
337
		$this->card = $card;
338
339
		return $this;
340
	}
341
342
	/**
343
	 * Get checkout reference
344
	 *
345
	 * @return  string
346
	 */
347
	public function getReference(): ?string
348
	{
349
		return $this->reference;
350
	}
351
352
	/**
353
	 * Set checkout reference
354
	 *
355
	 * @param  string  $reference  Checkout reference
356
	 *
357
	 * @return  CheckoutInterface
358
	 */
359
	public function setReference(?string $reference): CheckoutInterface
360
	{
361
		$this->reference = $reference;
362
363
		return $this;
364
	}
365
366
	/**
367
	 * @return mixed
368
	 */
369
	public function getType():? string
370
	{
371
		return $this->type;
372
	}
373
374
	/**
375
	 * @param mixed $type
376
	 * @return CheckoutInterface
377
	 */
378
	public function setType(?string $type = null): CheckoutInterface
379
	{
380
		$this->type = $type;
381
382
		return $this;
383
	}
384
385
	public function setInstallments(?string $installments): CheckoutInterface{
386
		$this->installments = $installments;
387
		return $this;
388
	}
389
390
	public function getInstallments(): string
391
	{
392
		return $this->installments;
393
	}
394
395
}
396