Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PackagingSearchDTO
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 fromRequest
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Domain\Packaging\DTOs;
4
5use Domain\Packaging\Enums\PackagingTypeEnum;
6use Domain\Shared\Interfaces\DataTransferObjectInterface;
7use Illuminate\Foundation\Http\FormRequest;
8
9final readonly class PackagingSearchDTO implements DataTransferObjectInterface
10{
11    public ?int $id;
12    public ?string $description;
13    public ?PackagingTypeEnum $type;
14    public ?int $codemb;
15
16    public function __construct(array $args)
17    {
18        $this->id = $args['id'] ?? null;
19        $this->description = $args['description'] ?? null;
20        $this->type = $args['type'] ?? null;
21        $this->codemb = $args['codemb'] ?? null;
22    }
23
24    public function toArray(): array
25    {
26        return [
27            'id' => $this->id,
28            'description' => $this->description,
29            'type' => $this->type?->value,
30            'codemb' => $this->codemb,
31        ];
32    }
33
34    public static function fromRequest(FormRequest $request): PackagingSearchDTO
35    {
36        return new self([
37            'id' => $request->validated('id'),
38            'description' => $request->validated('description'),
39            'type' => $request->validated('type') ? PackagingTypeEnum::tryFrom($request->validated('type')) : null,
40            'codemb' => $request->validated('codemb'),
41        ]);
42    }
43}