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
FamilySearchDTO
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
2 / 3
3.51
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
1
1<?php
2
3namespace Domain\Category\DTOs;
4
5use Domain\Shared\Interfaces\DataTransferObjectInterface;
6use Illuminate\Foundation\Http\FormRequest;
7
8readonly final class FamilySearchDTO implements DataTransferObjectInterface
9{
10    public ?int $id;
11    public ?string $name;
12    public array $origins;
13
14
15    public function __construct(array $args)
16    {
17        $this->id = $args['id'] ?? null;
18        $this->name = $args['name'];
19        $this->origins = $args['origins'] ?? [];
20    }
21
22    public function toArray(): array
23    {
24        return [
25            'id' => $this->id,
26            'name' => $this->name,
27            'origins' => $this->origins,
28        ];
29    }
30
31    public static function fromRequest(FormRequest $request): FamilySearchDTO
32    {
33        return new self([
34            'id' => $request->validated('id'),
35            'name' => $request->validated('name'),
36            'origins' => $request->validated('origins'),
37        ]);
38    }
39}