Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.75% covered (success)
93.75%
15 / 16
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AccountSummaryData
93.75% covered (success)
93.75%
15 / 16
50.00% covered (danger)
50.00%
1 / 2
2.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Account\Data;
6
7use JsonSerializable;
8
9/**
10 * Data transfer object for account summary information.
11 *
12 * All properties use camelCase. Repository handles snake_case conversion.
13 *
14 * All monetary values and ratios are stored as strings to preserve
15 * exact decimal precision from PostgreSQL NUMERIC types.
16 */
17final class AccountSummaryData implements JsonSerializable
18{
19    public int $accountId;
20
21    public int $investorId;
22
23    public string $accountNumber;
24
25    public string $balance;
26
27    public string $availableBalance;
28
29    public string $availableForLoan;
30
31    public string $maxLoanAmount;
32
33    public string $totalOutstandingLoans;
34
35    public string $earningsYtd;
36    public string $interestRate;
37
38    public string $loanToValueRatio;
39
40    public string $loanInterestRate;
41    public string $status;
42
43    public bool $hasAvailableCredit;
44
45    public bool $hasActiveLoans;
46
47    /**
48     * @param array{
49     *     accountId: int|string,
50     *     investorId: int|string,
51     *     accountNumber: string,
52     *     balance: string,
53     *     availableBalance: string,
54     *     availableForLoan: string,
55     *     maxLoanAmount: string,
56     *     totalOutstandingLoans: string,
57     *     earningsYtd: string,
58     *     interestRate: string,
59     *     loanToValueRatio: string,
60     *     loanInterestRate: string,
61     *     status: string,
62     *     hasAvailableCredit?: bool,
63     *     hasActiveLoans?: bool
64     * } $data
65     */
66    public function __construct(array $data)
67    {
68        $this->accountId = (int)$data['accountId'];
69        $this->investorId = (int)$data['investorId'];
70        $this->accountNumber = $data['accountNumber'];
71        $this->balance = $data['balance'];
72        $this->availableBalance = $data['availableBalance'];
73        $this->availableForLoan = $data['availableForLoan'];
74        $this->maxLoanAmount = $data['maxLoanAmount'];
75        $this->totalOutstandingLoans = $data['totalOutstandingLoans'];
76        $this->earningsYtd = $data['earningsYtd'];
77        $this->interestRate = $data['interestRate'];
78        $this->loanToValueRatio = $data['loanToValueRatio'];
79        $this->loanInterestRate = $data['loanInterestRate'];
80        $this->status = $data['status'];
81        $this->hasAvailableCredit = (bool)($data['hasAvailableCredit'] ?? false);
82        $this->hasActiveLoans = (bool)($data['hasActiveLoans'] ?? false);
83    }
84
85    /**
86     * @return array<string, string>
87     */
88    public function jsonSerialize(): array
89    {
90        return get_object_vars($this);
91    }
92}