Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
63.16% |
12 / 19 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| StockAdjustmentStoreItemDTO | |
63.16% |
12 / 19 |
|
66.67% |
2 / 3 |
3.45 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| fromRequest | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\StockAdjustment\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 final class StockAdjustmentStoreItemDTO implements DataTransferObjectInterface |
| 11 | { |
| 12 | |
| 13 | public Address $address; |
| 14 | public Product $product; |
| 15 | public float $amount; |
| 16 | public ?string $observation; |
| 17 | public ?string $priorityValue; |
| 18 | |
| 19 | public function __construct(array $args) |
| 20 | { |
| 21 | $this->address = $args['address']; |
| 22 | $this->product = $args['product']; |
| 23 | $this->amount = $args['amount']; |
| 24 | $this->observation = $args['observation'] ?? null; |
| 25 | $this->priorityValue = $args['priorityValue'] ?? null; |
| 26 | } |
| 27 | |
| 28 | public function toArray(): array |
| 29 | { |
| 30 | return [ |
| 31 | 'address' => $this->address->toArray(), |
| 32 | 'product' => $this->product->toArray(), |
| 33 | 'amount' => $this->amount, |
| 34 | 'observation' => $this->observation, |
| 35 | 'priorityValue' => $this->priorityValue |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | public static function fromRequest(FormRequest $request): StockAdjustmentStoreItemDTO |
| 40 | { |
| 41 | return new self([ |
| 42 | 'address' => Address::find($request->validated('address_id')), |
| 43 | 'product' => Product::find($request->validated('product_id')), |
| 44 | 'amount' => $request->validated('amount'), |
| 45 | 'observation' => $request->validated('observation'), |
| 46 | 'priorityValue' => $request->validated('priority_value') |
| 47 | ]); |
| 48 | } |
| 49 | } |