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
ExpenseView
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
 fromExpense
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 toArray
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\Expense\Application\Query;
6
7use App\Expense\Domain\Expense;
8
9final readonly class ExpenseView
10{
11    public function __construct(
12        public string $id,
13        public string $tripId,
14        public int $amount,
15        public string $currency,
16        public string $category,
17        public string $description,
18        public string $spentAt,
19        public ?int $convertedAmount = null,
20        public ?string $convertedCurrency = null,
21    ) {
22    }
23
24    public static function fromExpense(Expense $expense, ?int $convertedAmount = null, ?string $convertedCurrency = null): self
25    {
26        return new self(
27            $expense->id()->value(),
28            $expense->tripId()->value(),
29            $expense->money()->amount(),
30            $expense->money()->currency()->code(),
31            $expense->category()->value,
32            $expense->description(),
33            $expense->spentAt()->format('Y-m-d'),
34            $convertedAmount,
35            $convertedCurrency,
36        );
37    }
38
39    /**
40     * @return array{id: string, tripId: string, amount: int, currency: string, category: string, description: string, spentAt: string, convertedAmount: int|null, convertedCurrency: string|null}
41     */
42    public function toArray(): array
43    {
44        return [
45            'id' => $this->id,
46            'tripId' => $this->tripId,
47            'amount' => $this->amount,
48            'currency' => $this->currency,
49            'category' => $this->category,
50            'description' => $this->description,
51            'spentAt' => $this->spentAt,
52            'convertedAmount' => $this->convertedAmount,
53            'convertedCurrency' => $this->convertedCurrency,
54        ];
55    }
56}