Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
63.16% |
12 / 19 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FamilyDTO | |
63.16% |
12 / 19 |
|
66.67% |
2 / 3 |
3.45 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Category\DTOs; |
| 4 | |
| 5 | use App\Models\Category\Origin; |
| 6 | use Domain\Integration\DTOs\IntegrationFamilyDTO; |
| 7 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 8 | use Illuminate\Foundation\Http\FormRequest; |
| 9 | |
| 10 | readonly final class FamilyDTO implements DataTransferObjectInterface |
| 11 | { |
| 12 | public string $name; |
| 13 | public ?string $observation; |
| 14 | public IntegrationFamilyDTO $integrationFamilyDTO; |
| 15 | public Origin $origin; |
| 16 | |
| 17 | public function __construct(array $args) |
| 18 | { |
| 19 | $this->name = $args['name']; |
| 20 | $this->integrationFamilyDTO = new IntegrationFamilyDTO([ |
| 21 | 'integration_code' => $args['integration_code'], |
| 22 | 'integration_company' => $args['integration_company'], |
| 23 | ]); |
| 24 | $this->observation = $args['observation'] ?? null; |
| 25 | $this->origin = Origin::find($args['origin_id']); |
| 26 | } |
| 27 | |
| 28 | public function toArray(): array |
| 29 | { |
| 30 | return [ |
| 31 | 'name' => $this->name, |
| 32 | 'observation' => $this->observation, |
| 33 | 'origin_id' => $this->origin->getKey(), |
| 34 | ]; |
| 35 | } |
| 36 | |
| 37 | public static function fromRequest(FormRequest $request): DataTransferObjectInterface |
| 38 | { |
| 39 | return new self([ |
| 40 | 'name' => $request->validated('name'), |
| 41 | 'observation' => $request->validated('observation'), |
| 42 | 'origin_id' => $request->validated('origin_id'), |
| 43 | 'integration_code' => $request->validated('integration_code'), |
| 44 | 'integration_company' => $request->validated('integration_company'), |
| 45 | ]); |
| 46 | } |
| 47 | } |