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