Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
57.14% |
8 / 14 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TransferTaskProductDTO | |
57.14% |
8 / 14 |
|
66.67% |
2 / 3 |
3.71 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| fromRequest | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\TransferTask\DTOs; |
| 4 | |
| 5 | use App\Models\Address\Address; |
| 6 | use App\Models\Product\Product; |
| 7 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 8 | use Illuminate\Foundation\Http\FormRequest; |
| 9 | |
| 10 | readonly class TransferTaskProductDTO implements DataTransferObjectInterface |
| 11 | { |
| 12 | public Product $product; |
| 13 | public ?float $suggestionAmount; |
| 14 | public ?Address $suggestionOrigin; |
| 15 | public ?Address $suggestionDestination; |
| 16 | |
| 17 | |
| 18 | public function __construct(array $args) |
| 19 | { |
| 20 | $this->product = $args['product']; |
| 21 | $this->suggestionAmount = $args['suggestion_amount'] ?? null; |
| 22 | $this->suggestionOrigin = $args['suggestion_origin'] ?? null; |
| 23 | $this->suggestionDestination = $args['suggestion_destination'] ?? null; |
| 24 | } |
| 25 | |
| 26 | public function toArray(): array |
| 27 | { |
| 28 | return [ |
| 29 | 'product_id' => $this?->product->getKey(), |
| 30 | 'suggestion_amount' => $this->suggestionAmount, |
| 31 | ]; |
| 32 | } |
| 33 | |
| 34 | public static function fromRequest(FormRequest $request): TransferTaskProductDTO |
| 35 | { |
| 36 | return new self([ |
| 37 | 'product' => $request->validated('product_id'), |
| 38 | 'suggestion_amount' => $request->validated('suggestion_amount'), |
| 39 | 'suggestion_origin' => $request->validated('suggestion_origin_id'), |
| 40 | 'suggestion_destination' => $request->validated('suggestion_destination_id'), |
| 41 | ]); |
| 42 | } |
| 43 | } |