Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
63.64% covered (warning)
63.64%
14 / 22
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SearchUserDTO
63.64% covered (warning)
63.64%
14 / 22
66.67% covered (warning)
66.67%
2 / 3
3.43
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 fromRequest
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Domain\User\DTOs;
4
5use Domain\Shared\Interfaces\DataTransferObjectInterface;
6use Illuminate\Foundation\Http\FormRequest;
7
8readonly final class SearchUserDTO implements DataTransferObjectInterface
9{
10    public ?int $id;
11    public ?string $name;
12    public ?string $email;
13    public ?int $badge;
14    public array $accessLevels;
15    public ?array $sector;
16
17    public function __construct(array $args)
18    {
19        $this->id = $args['id'] ?? null;
20        $this->name = $args['name'] ?? null;
21        $this->email = $args['email'] ?? null;
22        $this->badge = $args['badge'] ?? null;
23        $this->accessLevels = $args['access_levels'] ?? [];
24        $this->sector = $args['sector'] ?? [];
25    }
26
27    public function toArray(): array
28    {
29        return [
30            'id' => $this->id,
31            'name' => $this->name,
32            'email' => $this->email,
33            'badge' => $this->badge,
34            'access_levels' => $this->accessLevels,
35            'sector' => $this->sector,
36        ];
37    }
38
39    public static function fromRequest(FormRequest $request): SearchUserDTO
40    {
41        return new self([
42            'id' => $request->validated('id'),
43            'name' => $request->validated('name'),
44            'email' => $request->validated('email'),
45            'badge' => $request->validated('badge'),
46            'access_levels' => $request->validated('access_levels'),
47            'sector' => $request->validated('sector'),
48        ]);
49    }
50}