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