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