Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PickingOrderDTO
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 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%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 fromRequest
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Domain\PickingOrder\DTOs;
4
5use App\Models\User;
6use Domain\PickingOrder\Enums\PickingOrderTypeEnum;
7use Domain\PickingOrder\Enums\PickingOrderTypeEnumV2;
8use Domain\Shared\Interfaces\DataTransferObjectInterface;
9use Illuminate\Foundation\Http\FormRequest;
10
11readonly final class PickingOrderDTO implements DataTransferObjectInterface
12{
13    public array $stockIOProducts;
14    private ?string $observation;
15    public User $responsible;
16    public ?PickingOrderTypeEnumV2 $type;
17    public array $details;
18    public bool $urgent;
19
20    public function __construct(array $args)
21    {
22        $this->observation = $args['observation'] ?? null;
23        $this->responsible = $args['responsible'];
24        $this->stockIOProducts = $args['stock_io_products'] ?? [];
25        $this->details = $args['details'] ?? [];
26        $this->urgent = $args['urgent'];
27        $this->type = PickingOrderTypeEnumV2::tryFrom($args['type']) ?? null;
28    }
29
30    public function toArray(): array
31    {
32        return [
33            'observation' => $this->observation,
34            'details' => $this->details,
35            'responsible_id' => $this->responsible->getKey(),
36            'urgent' => $this->urgent,
37            'type' => $this->type->value ?? PickingOrderTypeEnumV2::OUTPUT->value,
38        ];
39    }
40
41    public static function fromRequest(FormRequest $request): PickingOrderDTO
42    {
43        return new self([
44            'stock_io_products' => $request->validated('stock_io_products'),
45            'observation' => $request->validated('observation'),
46            'details' => $request->validated('details'),
47            'responsible' => User::find($request->validated('responsible_id')),
48            'urgent' => $request->validated('urgent'),
49            'type' => $request->validated('type'),
50        ]);
51    }
52}