Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
23.08% covered (danger)
23.08%
3 / 13
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ShippingPackagingAddProductDTO
23.08% covered (danger)
23.08%
3 / 13
33.33% covered (danger)
33.33%
1 / 3
7.10
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
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\ShippingPackaging\DTOs;
4
5use App\Models\StockIO\StockIOProduct;
6use Domain\Shared\Interfaces\DataTransferObjectInterface;
7use Illuminate\Foundation\Http\FormRequest;
8
9final readonly class ShippingPackagingAddProductDTO implements DataTransferObjectInterface
10{
11    public StockIOProduct $stockIOProduct;
12    public float $amount;
13    public string $production_order;
14
15    public function __construct(array $args)
16    {
17        $this->stockIOProduct = $args['stock_io_product'];
18        $this->amount = $args['amount'];
19        $this->production_order = $args['production_order'];
20    }
21
22    public function toArray(): array
23    {
24        return [
25            'stock_io_product' => $this->stockIOProduct->getKey(),
26            'amount' => $this->amount,
27            'production_order' => $this->production_order,
28        ];
29    }
30
31    public static function fromRequest(FormRequest $request): ShippingPackagingAddProductDTO
32    {
33        return new self([
34            'stock_io_product' =>  StockIOProduct::find($request->validated('stock_io_product_id')),
35            'amount' => $request->validated('amount'),
36            'production_order' => $request->validated('production_order'),
37        ]);
38    }
39}