Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LoanData
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fromRow
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
30
 toArray
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace 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 */
14final 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 $collateralDescription = null,
37        public ?string $requestedAt = null,
38        public ?string $activatedAt = null,
39        public ?string $createdAt = null,
40        public ?string $updatedAt = null,
41    ) {}
42
43    /**
44     * @param array<string, mixed> $row
45     */
46    public static function fromRow(array $row): self
47    {
48        return new self(
49            loanId: isset($row['loanId']) ? (int)$row['loanId'] : null,
50            accountId: isset($row['accountId']) ? (int)$row['accountId'] : null,
51            investorId: isset($row['investorId']) ? (int)$row['investorId'] : null,
52            investorName: $row['investorName'] ?? null,
53            investorEmail: $row['investorEmail'] ?? null,
54            accountNumber: $row['accountNumber'] ?? null,
55            accountBalance: $row['accountBalance'] ?? null,
56            loanType: $row['loanType'] ?? null,
57            principleAmount: $row['principleAmount'] ?? null,
58            outstandingBalance: $row['outstandingBalance'] ?? null,
59            interestRate: $row['interestRate'] ?? null,
60            termMonths: isset($row['termMonths']) ? (int)$row['termMonths'] : null,
61            monthlyPayment: $row['monthlyPayment'] ?? null,
62            totalInterest: $row['totalInterest'] ?? null,
63            totalRepayment: $row['totalRepayment'] ?? null,
64            startDate: $row['startDate'] ?? null,
65            maturityDate: $row['maturityDate'] ?? null,
66            nextPaymentDue: $row['nextPaymentDue'] ?? null,
67            status: $row['status'] ?? null,
68            collateralDescription: $row['collateralDescription'] ?? null,
69            requestedAt: $row['requestedAt'] ?? null,
70            activatedAt: $row['activatedAt'] ?? null,
71            createdAt: $row['createdAt'] ?? null,
72            updatedAt: $row['updatedAt'] ?? null,
73        );
74    }
75
76    /**
77     * @return array<string, mixed>
78     */
79    public function toArray(): array
80    {
81        return array_filter([
82            'loanId' => $this->loanId,
83            'accountId' => $this->accountId,
84            'investorId' => $this->investorId,
85            'investorName' => $this->investorName,
86            'investorEmail' => $this->investorEmail,
87            'accountNumber' => $this->accountNumber,
88            'accountBalance' => $this->accountBalance,
89            'loanType' => $this->loanType,
90            'principleAmount' => $this->principleAmount,
91            'outstandingBalance' => $this->outstandingBalance,
92            'interestRate' => $this->interestRate,
93            'termMonths' => $this->termMonths,
94            'monthlyPayment' => $this->monthlyPayment,
95            'totalInterest' => $this->totalInterest,
96            'totalRepayment' => $this->totalRepayment,
97            'startDate' => $this->startDate,
98            'maturityDate' => $this->maturityDate,
99            'nextPaymentDue' => $this->nextPaymentDue,
100            'status' => $this->status,
101            'collateralDescription' => $this->collateralDescription,
102            'requestedAt' => $this->requestedAt,
103            'activatedAt' => $this->activatedAt,
104            'createdAt' => $this->createdAt,
105            'updatedAt' => $this->updatedAt,
106        ], static fn($value): bool => $value !== null);
107    }
108}