Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AddressOrderGroupSearchDTO
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
2 / 3
4.91
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 fromRequest
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Domain\Address\DTOs;
4
5use App\Models\Address\Address;
6use App\Models\Team\Team;
7use Domain\Shared\Interfaces\DataTransferObjectInterface;
8use Illuminate\Foundation\Http\FormRequest;
9
10readonly final class AddressOrderGroupSearchDTO implements DataTransferObjectInterface
11{
12    public ?int $id;
13    public ?Address $address;
14    public Team $team;
15
16    public function __construct(array $args)
17    {
18        $this->id = $args['id'] ?? null;
19        $this->address = $args['address'];
20        $this->team = $args['team'];
21    }
22
23    public function toArray(): array
24    {
25        return [
26            'id' => $this->id,
27            'address_id' => $this->address?->getKey(),
28            'team_id' => $this->team->getKey(),
29        ];
30
31    }
32
33    public static function fromRequest(FormRequest $request): AddressOrderGroupSearchDTO
34    {
35        return new self([
36            'id' => $request->validated('id'),
37            'address' => $request->validated('address_id') ? Address::find($request->validated('address_id')) : null,
38            'team' => Team::find($request->validated('team_id')),
39        ]);
40    }
41}