Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
GenerateItemDTO
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
2 / 3
3.51
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 fromRequest
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Domain\Item\DTOs;
4
5use App\Models\Product\Product;
6use Domain\Integration\DTOs\IntegrationItemDTO;
7use Domain\Shared\Interfaces\DataTransferObjectInterface;
8use Illuminate\Foundation\Http\FormRequest;
9
10readonly final class GenerateItemDTO implements DataTransferObjectInterface
11{
12    public Product $product;
13    public float   $amount;
14    public ?string $priority_value;
15
16    public function __construct(array $args)
17    {
18        $this->product        = $args['product'];
19        $this->amount         = $args['amount'];
20        $this->priority_value = $args['priority_value'] ?? null;
21    }
22
23    public function toArray(): array
24    {
25        return [
26            'product'        => $this->product,
27            'amount'         => $this->amount,
28            'priority_value' => $this->priority_value,
29        ];
30    }
31
32    public static function fromRequest(FormRequest $request): GenerateItemDTO
33    {
34        return new self([
35            'product'        => Product::find($request->validated('product_id')),
36            'amount'         => $request->validated('amount'),
37            'priority_value' => $request->validated('priority_value'),
38        ]);
39    }
40}