Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TransactionData
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 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%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Transaction\Data;
6
7use App\Support\Row;
8use JsonSerializable;
9
10final readonly class TransactionData implements JsonSerializable
11{
12    public function __construct(
13        public int $transactionId,
14        public int $accountId,
15        public string $transactionType,
16        public string $amount,
17        public string $balanceAfter,
18        public ?string $description,
19        public ?string $referenceNumber,
20        public string $createdAt,
21        public string $status,
22    ) {}
23
24    /**
25     * @param array<mixed> $data
26     */
27    public static function fromRow(array $data): self
28    {
29        return new self(
30            transactionId: Row::int($data, 'transactionId'),
31            accountId: Row::int($data, 'accountId'),
32            transactionType: Row::string($data, 'transactionType'),
33            amount: Row::string($data, 'amount'),
34            balanceAfter: Row::string($data, 'balanceAfter'),
35            description: Row::nullableString($data, 'description'),
36            referenceNumber: Row::nullableString($data, 'referenceNumber'),
37            createdAt: Row::string($data, 'createdAt'),
38            status: Row::string($data, 'status'),
39        );
40    }
41
42    /**
43     * @return array<string, int|string|null>
44     */
45    public function jsonSerialize(): array
46    {
47        return [
48            'transactionId' => $this->transactionId,
49            'accountId' => $this->accountId,
50            'transactionType' => $this->transactionType,
51            'amount' => $this->amount,
52            'balanceAfter' => $this->balanceAfter,
53            'description' => $this->description,
54            'referenceNumber' => $this->referenceNumber,
55            'createdAt' => $this->createdAt,
56            'status' => $this->status,
57        ];
58    }
59}