Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
20 / 30
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ExportDevolutionRequestSeniorDTO
66.67% covered (warning)
66.67%
20 / 30
66.67% covered (warning)
66.67%
2 / 3
3.33
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 fromRequest
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\Request\DTOs;
4
5use Illuminate\Foundation\Http\FormRequest;
6
7use Domain\Shared\Interfaces\DataTransferObjectInterface;
8
9readonly final class ExportDevolutionRequestSeniorDTO implements DataTransferObjectInterface
10{
11    public string $identificadorSistema;
12    public int $codEmp;
13    public int $codFil;
14    public int|string|null $numEme;
15    public ?int $identificadorExterno;
16    public int $tipoProcessamento;
17    public ?string $tipoOperacao;
18    /** @var RequestsSeniorDTO[] */
19    public array $itens;
20
21    public function __construct(array $args)
22    {
23        $this->identificadorSistema = $args['identificadorSistema'];
24        $this->codEmp               = $args['codEmp'];
25        $this->codFil               = $args['codFil'];
26        $this->numEme               = $args['numEme'] ?? null;
27        $this->tipoProcessamento    = $args['tipoProcessamento'];
28        $this->itens                = $args['itens'];
29        $this->identificadorExterno = $args['identificadorExterno'] ?? null;
30        $this->tipoOperacao         = $args['tipoOperacao'] ?? null;
31
32    }
33
34    public function toArray(): array
35    {
36        return [
37            'identificadorSistema' => $this->identificadorSistema,
38            'dadosGerais' => [
39                'codEmp'               => $this->codEmp,
40                'codFil'               => $this->codFil,
41                'numEme'               => $this->numEme,
42                'tipoProcessamento'    => $this->tipoProcessamento,
43                'identificadorExterno' => $this->identificadorExterno,
44                'tipoOperacao'         => $this->tipoOperacao,
45                'itens'                => $this->itens,
46            ],
47        ];
48    }
49
50    public static function fromRequest(FormRequest $request): ExportDevolutionRequestSeniorDTO
51    {
52        return new self([
53            'identificadorSistema' => $request->validated('identificadorSistema'),
54            'codEmp'               => $request->validated('codEmp'),
55            'codFil'               => $request->validated('codFil'),
56            'numEme'               => $request->validated('numEme'),
57            'tipoProcessamento'    => $request->validated('tipoProcessamento'),
58            'itens'                => $request->validated('itens'),
59            'identificadorExterno' => $request->validated('identificadorExterno'),
60            'tipoOperacao'         => $request->validated('tipoOperacao'),
61
62        ]);
63    }
64}