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