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