Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
6 / 18 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ItemDTO | |
33.33% |
6 / 18 |
|
33.33% |
1 / 3 |
5.67 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| fromRequest | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Item\DTOs; |
| 4 | |
| 5 | use Domain\Integration\DTOs\IntegrationItemDTO; |
| 6 | use Domain\Item\Interfaces\IsItemInterface; |
| 7 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 8 | use Illuminate\Foundation\Http\FormRequest; |
| 9 | |
| 10 | readonly final class ItemDTO implements DataTransferObjectInterface |
| 11 | { |
| 12 | public IsItemInterface $target; |
| 13 | public float $amount; |
| 14 | public IntegrationItemDTO $itemIntegrationDTO; |
| 15 | |
| 16 | public function __construct(array $args) |
| 17 | { |
| 18 | $this->target = $args['target']; |
| 19 | $this->amount = $args['amount']; |
| 20 | $this->itemIntegrationDTO = new IntegrationItemDTO([ |
| 21 | 'production_order' => $args['production_order'] ?? null, |
| 22 | 'movement_date' => $args['movement_date'] ?? null, |
| 23 | ]); |
| 24 | } |
| 25 | |
| 26 | public function toArray(): array |
| 27 | { |
| 28 | return [ |
| 29 | 'target' => $this->target->getKey(), |
| 30 | 'amount' => $this->amount, |
| 31 | 'production_order' => $this->itemIntegrationDTO->productionOrder, |
| 32 | 'movement_date' => $this->itemIntegrationDTO->movementDate, |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | public static function fromRequest(FormRequest $request): ItemDTO |
| 37 | { |
| 38 | return new self([ |
| 39 | 'target' => $request->validated('target'), |
| 40 | 'amount' => $request->validated('amount'), |
| 41 | 'production_order' => $request->validated('production_order'), |
| 42 | 'movement_date' => $request->validated('movement_date'), |
| 43 | ]); |
| 44 | } |
| 45 | } |