Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
79.41% covered (warning)
79.41%
27 / 34
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
IntegrationStockOutputWarehouseProductDTO
79.41% covered (warning)
79.41%
27 / 34
66.67% covered (warning)
66.67%
2 / 3
5.22
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
3
 fromRequest
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\Integration\DTOs;
4
5use Domain\Shared\Interfaces\DataTransferObjectInterface;
6use Illuminate\Foundation\Http\FormRequest;
7
8readonly final class IntegrationStockOutputWarehouseProductDTO implements DataTransferObjectInterface
9{
10    public ?string $request_number;
11    public ?string $product_code;
12    public ?string $derivation_code;
13    public ?float $request_quantity;
14    public ?int $request_sequence;
15    public null|string|int $purchase_solicitation_branch;
16    public null|string|int $purchase_solicitation_number;
17    public null|string|int $purchase_solicitation_sequence;
18    public null|string|float $purchase_solicitation_quantity;
19    public ?string $obsEme;
20
21
22    public function __construct(array $args)
23    {
24        $this->request_number   = $args['request_number'] ?? "";
25        $this->product_code     = $args['product_code'] ?? "";
26        $this->derivation_code  = $args['derivation_code'] ?? "";
27        $this->request_quantity = $args['request_quantity'] ?? 0;
28        $this->request_sequence = $args['request_sequence'] ?? 0;
29        $this->purchase_solicitation_branch = $args['purchase_solicitation_branch'] ?? null;
30        $this->purchase_solicitation_number = $args['purchase_solicitation_number'] ?? null;
31        $this->purchase_solicitation_sequence = $args['purchase_solicitation_sequence'] ?? null;
32        $this->purchase_solicitation_quantity = $args['purchase_solicitation_quantity'] ?? null;
33        $this->obsEme = $args['obsEme'] ?? null;
34    }
35
36    public function toArray(): array
37    {
38        $parameters = [
39            'request_number'   => $this->request_number,
40            'product_code'     => $this->product_code,
41            'derivation_code'  => $this->derivation_code,
42            'request_quantity' => $this->request_quantity,
43            'request_sequence' => $this->request_sequence,
44            'obsEme'           => $this->obsEme,
45        ];
46
47        foreach ([
48            'purchase_solicitation_branch',
49            'purchase_solicitation_number',
50            'purchase_solicitation_sequence',
51            'purchase_solicitation_quantity',
52        ] as $key) {
53            if (!is_null($this->{$key})) {
54                $parameters[$key] = $this->{$key};
55            }
56        }
57
58        return $parameters;
59    }
60
61    public static function fromRequest(FormRequest $request): IntegrationStockOutputWarehouseProductDTO
62    {
63        return new self([
64            'request_number'   => $request->validated('request_number'),
65            'product_code'     => $request->validated('product_code'),
66            'derivation_code'  => $request->validated('derivation_code'),
67            'request_quantity' => $request->validated('request_quantity'),
68            'request_sequence' => $request->validated('request_sequence'),
69        ]);
70    }
71}