Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
57.14% covered (warning)
57.14%
12 / 21
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ItemProductDTO
57.14% covered (warning)
57.14%
12 / 21
66.67% covered (warning)
66.67%
2 / 3
3.71
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%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 fromRequest
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\Item\DTOs;
4
5use Illuminate\Foundation\Http\FormRequest;
6
7use Domain\Integration\DTOs\IntegrationItemWarehouseDTO;
8use Domain\Item\Interfaces\IsItemInterface;
9use Domain\Shared\Interfaces\DataTransferObjectInterface;
10
11readonly final class ItemProductDTO implements DataTransferObjectInterface
12{
13    public IsItemInterface $target;
14    public float $amount;
15    public IntegrationItemWarehouseDTO $itemIntegrationDTO;
16
17    public function __construct(array $args)
18    {
19        $this->target = $args['target'];
20        $this->amount = $args['amount'];
21        $this->itemIntegrationDTO = new IntegrationItemWarehouseDTO([
22            'priority_field' => $args['itemIntegrationDTO']['priority_field'],
23            'priority_value' => $args['itemIntegrationDTO']['priority_value'],
24        ]);
25    }
26
27    public function toArray(): array
28    {
29        return [
30            'target' => $this->target->getKey(),
31            'amount' => $this->amount,
32            'priority_field' => $this->itemIntegrationDTO->priorityField,
33            'priority_value' => $this->itemIntegrationDTO->priorityValue,
34        ];
35    }
36
37    public static function fromRequest(FormRequest $request): ItemProductDTO
38    {
39        $data = $request->validated();
40
41        return new self([
42            'target' => $data['target'],
43            'amount' => (float) $data['amount'],
44            'itemIntegrationDTO' => [
45                'priority_field' => $data['priority_field'],
46                'priority_value' => $data['priority_value'],
47            ],
48        ]);
49    }
50}