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