Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
29 / 29 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| DisbursementData | |
100.00% |
29 / 29 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromRow | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Disbursement\Data; |
| 6 | |
| 7 | use App\Support\Row; |
| 8 | |
| 9 | /** |
| 10 | * Immutable DTO for a row in lending.disbursements. |
| 11 | * |
| 12 | * Money values are strings (NUMERIC(15,2) in Postgres). Status is one of |
| 13 | * 'pending_disbursement' | 'disbursed' | 'cancelled'. |
| 14 | */ |
| 15 | final readonly class DisbursementData |
| 16 | { |
| 17 | public function __construct( |
| 18 | public ?int $disbursementId = null, |
| 19 | public ?int $loanId = null, |
| 20 | public ?string $requestedAmount = null, |
| 21 | public ?string $confirmedAmount = null, |
| 22 | public ?string $originationFee = null, |
| 23 | public ?string $netDisbursementAmount = null, |
| 24 | public ?string $bankReference = null, |
| 25 | public ?string $status = null, |
| 26 | public ?string $disbursedDate = null, |
| 27 | public ?int $disbursedBy = null, |
| 28 | public ?string $createdAt = null, |
| 29 | public ?string $updatedAt = null, |
| 30 | ) {} |
| 31 | |
| 32 | /** |
| 33 | * @param array<mixed> $row |
| 34 | */ |
| 35 | public static function fromRow(array $row): self |
| 36 | { |
| 37 | return new self( |
| 38 | disbursementId: Row::nullableInt($row, 'disbursementId'), |
| 39 | loanId: Row::nullableInt($row, 'loanId'), |
| 40 | requestedAmount: Row::nullableString($row, 'requestedAmount'), |
| 41 | confirmedAmount: Row::nullableString($row, 'confirmedAmount'), |
| 42 | originationFee: Row::nullableString($row, 'originationFee'), |
| 43 | netDisbursementAmount: Row::nullableString($row, 'netDisbursementAmount'), |
| 44 | bankReference: Row::nullableString($row, 'bankReference'), |
| 45 | status: Row::nullableString($row, 'status'), |
| 46 | disbursedDate: Row::nullableString($row, 'disbursedDate'), |
| 47 | disbursedBy: Row::nullableInt($row, 'disbursedBy'), |
| 48 | createdAt: Row::nullableString($row, 'createdAt'), |
| 49 | updatedAt: Row::nullableString($row, 'updatedAt'), |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return array<string, mixed> |
| 55 | */ |
| 56 | public function toArray(): array |
| 57 | { |
| 58 | return array_filter([ |
| 59 | 'disbursementId' => $this->disbursementId, |
| 60 | 'loanId' => $this->loanId, |
| 61 | 'requestedAmount' => $this->requestedAmount, |
| 62 | 'confirmedAmount' => $this->confirmedAmount, |
| 63 | 'originationFee' => $this->originationFee, |
| 64 | 'netDisbursementAmount' => $this->netDisbursementAmount, |
| 65 | 'bankReference' => $this->bankReference, |
| 66 | 'status' => $this->status, |
| 67 | 'disbursedDate' => $this->disbursedDate, |
| 68 | 'disbursedBy' => $this->disbursedBy, |
| 69 | 'createdAt' => $this->createdAt, |
| 70 | 'updatedAt' => $this->updatedAt, |
| 71 | ], static fn($value): bool => $value !== null); |
| 72 | } |
| 73 | } |