Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
33.33% covered (danger)
33.33%
7 / 21
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PickItemWarehouseDTO
33.33% covered (danger)
33.33%
7 / 21
33.33% covered (danger)
33.33%
1 / 3
5.67
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 fromRequest
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\PickingOrder\DTOs;
4
5use App\Models\StockIO\StockIOProduct;
6use Domain\Integration\DTOs\IntegrationItemWarehouseDTO;
7use Domain\Shared\Interfaces\DataTransferObjectInterface;
8use Domain\Shared\Support\DecimalNormalizer;
9use Illuminate\Foundation\Http\FormRequest;
10
11final readonly class PickItemWarehouseDTO implements DataTransferObjectInterface
12{
13    public StockIOProduct $stockIOProduct;
14
15    public float $amount;
16
17    public IntegrationItemWarehouseDTO $integrationItemDTO;
18
19    public ?string $observation;
20
21    public function __construct(array $args)
22    {
23        $this->stockIOProduct = $args['stock_io_product'];
24        $this->amount = DecimalNormalizer::toFloat($args['amount']);
25        $this->integrationItemDTO = new IntegrationItemWarehouseDTO([
26            'priority_value' => $args['priority_value'],
27            'priority_field' => $args['priority_field'],
28        ]);
29        $this->observation = $args['observation'] ?? null;
30    }
31
32    public function toArray(): array
33    {
34        return [
35            'stock_io_product_id' => $this->stockIOProduct->getKey(),
36            'amount' => $this->amount,
37            'observation' => $this->observation,
38            'priority_value' => $this->integrationItemDTO->priorityValue,
39            'priority_field' => $this->integrationItemDTO->priorityField,
40        ];
41    }
42
43    public static function fromRequest(FormRequest $request): PickItemWarehouseDTO
44    {
45        return new self([
46            'stock_io_product' => StockIOProduct::find($request->validated('stock_io_product_id')),
47            'amount' => $request->validated('amount'),
48            'observation' => $request->validated('observation'),
49            'priority_value' => $request->validated('priority_value'),
50            'priority_field' => $request->validated('priority_field'),
51        ]);
52    }
53}