Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.77% |
33 / 65 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LoanData | |
50.77% |
33 / 65 |
|
66.67% |
2 / 3 |
18.66 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromRow | |
100.00% |
32 / 32 |
|
100.00% |
1 / 1 |
7 | |||
| toArray | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Loan\Data; |
| 6 | |
| 7 | /** |
| 8 | * Represents a comprehensive data transfer object for loan information including investor details, account data, and loan terms. |
| 9 | * |
| 10 | * This immutable value object encapsulates all relevant information about a loan, including associated investor and account details, |
| 11 | * financial terms, payment schedules, and timestamps for various lifecycle events. All properties are nullable to accommodate |
| 12 | * partial data scenarios. |
| 13 | */ |
| 14 | final readonly class LoanData |
| 15 | { |
| 16 | public function __construct( |
| 17 | public ?int $loanId = null, |
| 18 | public ?int $accountId = null, |
| 19 | public ?int $investorId = null, |
| 20 | public ?string $investorName = null, |
| 21 | public ?string $investorEmail = null, |
| 22 | public ?string $accountNumber = null, |
| 23 | public ?string $accountBalance = null, |
| 24 | public ?string $loanType = null, |
| 25 | public ?string $principleAmount = null, |
| 26 | public ?string $outstandingBalance = null, |
| 27 | public ?string $interestRate = null, |
| 28 | public ?int $termMonths = null, |
| 29 | public ?string $monthlyPayment = null, |
| 30 | public ?string $totalInterest = null, |
| 31 | public ?string $totalRepayment = null, |
| 32 | public ?string $startDate = null, |
| 33 | public ?string $maturityDate = null, |
| 34 | public ?string $nextPaymentDue = null, |
| 35 | public ?string $status = null, |
| 36 | public ?string $requestedAmount = null, |
| 37 | public ?int $requestedTermMonths = null, |
| 38 | public ?string $collateralDescription = null, |
| 39 | public ?string $requestedAt = null, |
| 40 | public ?string $reviewedAt = null, |
| 41 | public ?int $reviewedBy = null, |
| 42 | public ?string $activatedAt = null, |
| 43 | public ?string $denialReason = null, |
| 44 | public ?string $approvalNotes = null, |
| 45 | public ?string $createdAt = null, |
| 46 | public ?string $updatedAt = null, |
| 47 | ) {} |
| 48 | |
| 49 | /** |
| 50 | * @param array<string, mixed> $row |
| 51 | */ |
| 52 | public static function fromRow(array $row): self |
| 53 | { |
| 54 | return new self( |
| 55 | loanId: isset($row['loanId']) ? (int)$row['loanId'] : null, |
| 56 | accountId: isset($row['accountId']) ? (int)$row['accountId'] : null, |
| 57 | investorId: isset($row['investorId']) ? (int)$row['investorId'] : null, |
| 58 | investorName: $row['investorName'] ?? null, |
| 59 | investorEmail: $row['investorEmail'] ?? null, |
| 60 | accountNumber: $row['accountNumber'] ?? null, |
| 61 | accountBalance: $row['accountBalance'] ?? null, |
| 62 | loanType: $row['loanType'] ?? null, |
| 63 | principleAmount: $row['principleAmount'] ?? null, |
| 64 | outstandingBalance: $row['outstandingBalance'] ?? null, |
| 65 | interestRate: $row['interestRate'] ?? null, |
| 66 | termMonths: isset($row['termMonths']) ? (int)$row['termMonths'] : null, |
| 67 | monthlyPayment: $row['monthlyPayment'] ?? null, |
| 68 | totalInterest: $row['totalInterest'] ?? null, |
| 69 | totalRepayment: $row['totalRepayment'] ?? null, |
| 70 | startDate: $row['startDate'] ?? null, |
| 71 | maturityDate: $row['maturityDate'] ?? null, |
| 72 | nextPaymentDue: $row['nextPaymentDue'] ?? null, |
| 73 | status: $row['status'] ?? null, |
| 74 | requestedAmount: $row['requestedAmount'] ?? null, |
| 75 | requestedTermMonths: isset($row['requestedTermMonths']) ? (int)$row['requestedTermMonths'] : null, |
| 76 | collateralDescription: $row['collateralDescription'] ?? null, |
| 77 | requestedAt: $row['requestedAt'] ?? null, |
| 78 | reviewedAt: $row['reviewedAt'] ?? null, |
| 79 | reviewedBy: isset($row['reviewedBy']) ? (int)$row['reviewedBy'] : null, |
| 80 | activatedAt: $row['activatedAt'] ?? null, |
| 81 | denialReason: $row['denialReason'] ?? null, |
| 82 | approvalNotes: $row['approvalNotes'] ?? null, |
| 83 | createdAt: $row['createdAt'] ?? null, |
| 84 | updatedAt: $row['updatedAt'] ?? null, |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return array<string, mixed> |
| 90 | */ |
| 91 | public function toArray(): array |
| 92 | { |
| 93 | return array_filter([ |
| 94 | 'loanId' => $this->loanId, |
| 95 | 'accountId' => $this->accountId, |
| 96 | 'investorId' => $this->investorId, |
| 97 | 'investorName' => $this->investorName, |
| 98 | 'investorEmail' => $this->investorEmail, |
| 99 | 'accountNumber' => $this->accountNumber, |
| 100 | 'accountBalance' => $this->accountBalance, |
| 101 | 'loanType' => $this->loanType, |
| 102 | 'principleAmount' => $this->principleAmount, |
| 103 | 'outstandingBalance' => $this->outstandingBalance, |
| 104 | 'interestRate' => $this->interestRate, |
| 105 | 'termMonths' => $this->termMonths, |
| 106 | 'monthlyPayment' => $this->monthlyPayment, |
| 107 | 'totalInterest' => $this->totalInterest, |
| 108 | 'totalRepayment' => $this->totalRepayment, |
| 109 | 'startDate' => $this->startDate, |
| 110 | 'maturityDate' => $this->maturityDate, |
| 111 | 'nextPaymentDue' => $this->nextPaymentDue, |
| 112 | 'status' => $this->status, |
| 113 | 'requestedAmount' => $this->requestedAmount, |
| 114 | 'requestedTermMonths' => $this->requestedTermMonths, |
| 115 | 'collateralDescription' => $this->collateralDescription, |
| 116 | 'requestedAt' => $this->requestedAt, |
| 117 | 'reviewedAt' => $this->reviewedAt, |
| 118 | 'reviewedBy' => $this->reviewedBy, |
| 119 | 'activatedAt' => $this->activatedAt, |
| 120 | 'denialReason' => $this->denialReason, |
| 121 | 'approvalNotes' => $this->approvalNotes, |
| 122 | 'createdAt' => $this->createdAt, |
| 123 | 'updatedAt' => $this->updatedAt, |
| 124 | ], static fn($value): bool => $value !== null); |
| 125 | } |
| 126 | } |