-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathEligibilityQueryDto.php
More file actions
57 lines (49 loc) · 1.77 KB
/
Copy pathEligibilityQueryDto.php
File metadata and controls
57 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Alma\Client\Application\DTO;
use InvalidArgumentException;
class EligibilityQueryDto implements DtoInterface {
private int $installmentsCount = 1;
private int $deferredDays = 0;
private int $deferredMonths = 0;
public function __construct(
int $installmentsCount
) {
$this->setInstallmentsCount($installmentsCount);
}
public function setInstallmentsCount(int $installmentsCount): self {
if ($installmentsCount <= 0 || $installmentsCount > 12) {
throw new InvalidArgumentException("Installments count must be between 1 and 12.");
}
$this->installmentsCount = $installmentsCount;
return $this;
}
public function setDeferredDays(int $deferredDays): self {
if ($deferredDays < 0) {
throw new InvalidArgumentException("Deferred days count must be positive.");
}
$this->deferredDays = $deferredDays;
return $this;
}
public function setDeferredMonths(int $deferredMonths): self {
if ($deferredMonths < 0) {
throw new InvalidArgumentException("Deferred months must be positive.");
}
$this->deferredMonths = $deferredMonths;
return $this;
}
/**
* Convert the Dto to an array.
* This method prepares the DTO for serialization or API requests.
*
* @return array
*/
public function toArray(): array {
return array_filter([
'installments_count' => $this->installmentsCount,
'deferred_days' => $this->deferredDays,
'deferred_months' => $this->deferredMonths,
], function($value) {
return $value !== null && $value !== '' && !(is_array($value) && empty($value));
});
}
}