Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AccountData
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Account\Data;
6
7use JsonSerializable;
8
9/**
10 * Data transfer object for account information.
11 *
12 * All properties use camelCase. Repository handles snake_case conversion.
13 *
14 * Monetary values are stored as strings to preserve exact decimal
15 * precision from PostgreSQL NUMERIC types.
16 */
17final class AccountData 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 $interestRate;
32
33    public string $loanToValueRatio;
34
35    public string $currency;
36
37    public string $openedDate;
38
39    public string $status;
40
41    public ?string $bankAccountId;
42
43    public string $bankAccountStatus;
44
45    public string $createdAt;
46
47    public string $updatedAt;
48
49    /**
50     * @param array{
51     *     accountId: int|string,
52     *     investorId: int|string,
53     *     accountNumber: string,
54     *     balance: string,
55     *     availableBalance: string,
56     *     availableForLoan: string,
57     *     interestRate: string,
58     *     loanToValueRatio: string,
59     *     currency: string,
60     *     openedDate: string,
61     *     status: string,
62     *     bankAccountId?: string|null,
63     *     bankAccountStatus: string,
64     *     createdAt: string,
65     *     updatedAt: string
66     * } $data
67     */
68    public function __construct(array $data)
69    {
70        // Expects camelCase from repository
71        $this->accountId = (int)$data['accountId'];
72        $this->investorId = (int)$data['investorId'];
73        $this->accountNumber = $data['accountNumber'];
74
75        $this->balance = $data['balance'];
76        $this->availableBalance = $data['availableBalance'];
77        $this->availableForLoan = $data['availableForLoan'];
78        $this->interestRate = $data['interestRate'];
79        $this->loanToValueRatio = $data['loanToValueRatio'];
80        $this->currency = $data['currency'];
81        $this->openedDate = $data['openedDate'];
82        $this->status = $data['status'];
83        $this->bankAccountId = $data['bankAccountId'] ?? null;
84        $this->bankAccountStatus = $data['bankAccountStatus'];
85        $this->createdAt = $data['createdAt'];
86        $this->updatedAt = $data['updatedAt'];
87    }
88
89    /**
90     * Prepares the object for JSON serialization by returning its properties as an associative array.
91     *
92     * @return array<string, mixed> an associative array containing the serialized representation of the object
93     */
94    public function jsonSerialize(): array
95    {
96        return get_object_vars($this);
97    }
98}