Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
63.16% covered (warning)
63.16%
12 / 19
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProductMeasureDTO
63.16% covered (warning)
63.16%
12 / 19
66.67% covered (warning)
66.67%
2 / 3
3.45
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
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 fromRequest
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\Product\DTOs;
4
5use Domain\Shared\Interfaces\DataTransferObjectInterface;
6use Illuminate\Foundation\Http\FormRequest;
7
8readonly final class ProductMeasureDTO implements DataTransferObjectInterface
9{
10    private ?float $width;
11    private ?float $height;
12    private ?float $depth;
13    private float $net_weight;
14    private float $gross_weight;
15
16    public function __construct(array $args)
17    {
18        $this->width = $args['width'] ?? null;
19        $this->height = $args['height'] ?? null;
20        $this->depth = $args['depth'] ?? null;
21        $this->net_weight = $args['net_weight'];
22        $this->gross_weight = $args['gross_weight'];
23    }
24
25    public function toArray(): array
26    {
27        return [
28            'width' => $this->width,
29            'height' => $this->height,
30            'depth' => $this->depth,
31            'net_weight' => $this->net_weight,
32            'gross_weight' => $this->gross_weight,
33        ];
34    }
35
36    public static function fromRequest(FormRequest $request): ProductMeasureDTO
37    {
38        return new self([
39            'width' => $request->validated('width'),
40            'height' => $request->validated('height'),
41            'depth' => $request->validated('depth'),
42            'net_weight' => $request->validated('net_weight'),
43            'gross_weight' => $request->validated('gross_weight'),
44        ]);
45    }
46}