Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
57.14% |
12 / 21 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ItemProductDTO | |
57.14% |
12 / 21 |
|
66.67% |
2 / 3 |
3.71 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Item\DTOs; |
| 4 | |
| 5 | use Illuminate\Foundation\Http\FormRequest; |
| 6 | |
| 7 | use Domain\Integration\DTOs\IntegrationItemWarehouseDTO; |
| 8 | use Domain\Item\Interfaces\IsItemInterface; |
| 9 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 10 | |
| 11 | readonly 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 | } |