Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TripView
100.00% covered (success)
100.00%
27 / 27
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
 fromTrip
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Trip\Application\Query;
6
7use App\Trip\Domain\Trip;
8use App\Trip\Domain\ValueObject\TripRole;
9
10final readonly class TripView
11{
12    public function __construct(
13        public string $id,
14        public string $ownerId,
15        public string $name,
16        public string $destination,
17        public string $startDate,
18        public string $endDate,
19        public string $currency,
20        public int $budgetAmount,
21        public string $role,
22        public ?string $imageUrl,
23        public bool $archived,
24    ) {
25    }
26
27    /** $imageUrl is the signed, expiring link minted by SignedImageUrl (null when there is no image). */
28    public static function fromTrip(Trip $trip, TripRole $role, ?string $imageUrl = null): self
29    {
30        return new self(
31            $trip->id()->value(),
32            $trip->ownerId()->value(),
33            $trip->name(),
34            $trip->destination(),
35            $trip->dateRange()->start()->format('Y-m-d'),
36            $trip->dateRange()->end()->format('Y-m-d'),
37            $trip->currency()->code(),
38            $trip->budget()->amount(),
39            $role->value,
40            $imageUrl,
41            $trip->isArchived(),
42        );
43    }
44
45    /**
46     * @return array{id: string, ownerId: string, name: string, destination: string, startDate: string, endDate: string, currency: string, budgetAmount: int, role: string, imageUrl: string|null, archived: bool}
47     */
48    public function toArray(): array
49    {
50        return [
51            'id' => $this->id,
52            'ownerId' => $this->ownerId,
53            'name' => $this->name,
54            'destination' => $this->destination,
55            'startDate' => $this->startDate,
56            'endDate' => $this->endDate,
57            'currency' => $this->currency,
58            'budgetAmount' => $this->budgetAmount,
59            'role' => $this->role,
60            'imageUrl' => $this->imageUrl,
61            'archived' => $this->archived,
62        ];
63    }
64}