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