Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| RequestDeliveryDTO | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Request\DTOs; |
| 4 | |
| 5 | use App\Models\Request\RequestItem; |
| 6 | use App\Models\User; |
| 7 | use Illuminate\Foundation\Http\FormRequest; |
| 8 | |
| 9 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 10 | |
| 11 | readonly final class RequestDeliveryDTO implements DataTransferObjectInterface |
| 12 | { |
| 13 | public array $receiver; |
| 14 | public ?User $store_keeper; |
| 15 | public array $picking_orders; |
| 16 | public ?string $observation; |
| 17 | |
| 18 | public function __construct(array $args) |
| 19 | { |
| 20 | $this->receiver = $args['receiver']; |
| 21 | $this->store_keeper = $args['store_keeper'] ?? null; |
| 22 | $this->picking_orders = $args['picking_orders']; |
| 23 | $this->observation = $args['observation'] ?? null; |
| 24 | } |
| 25 | |
| 26 | public function toArray(): array |
| 27 | { |
| 28 | return [ |
| 29 | 'receiver' => $this->receiver, |
| 30 | 'store_keeper' => $this->store_keeper, |
| 31 | 'picking_orders' => $this->picking_orders, |
| 32 | 'observation' => $this->observation, |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | public static function fromRequest(FormRequest $request): RequestDeliveryDTO |
| 37 | { |
| 38 | return new self([ |
| 39 | 'receiver' => $request->validated('receiver'), |
| 40 | 'store_keeper' => User::find($request->validated('store_keeper')), |
| 41 | 'picking_orders' => $request->validated('picking_orders'), |
| 42 | 'observation' => $request->validated('observation'), |
| 43 | ]); |
| 44 | } |
| 45 | } |