Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SearchInvoiceItemDTO
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 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\Invoice\DTOs;
4
5use Carbon\Carbon;
6use Domain\Shared\Interfaces\DataTransferObjectInterface;
7use Illuminate\Foundation\Http\FormRequest;
8
9readonly final class SearchInvoiceItemDTO implements DataTransferObjectInterface
10{
11    public ?int $id;
12    public ?array $invoices;
13    public ?array $unit_measurement;
14    public ?Carbon $created_at;
15    public ?Carbon $updated_at;
16
17    public function __construct(array $args)
18    {
19        $this->id = $args['id'] ?? null;
20        $this->invoices = $args['invoices'] ?? [];
21        $this->unit_measurement = $args['unit_measurement'] ?? [];
22        $this->created_at = $args['created_at'] ? Carbon::parse($args['created_at']) : null;
23        $this->updated_at = $args['updated_at'] ? Carbon::parse($args['updated_at']) : null;
24    }
25
26    public function toArray(): array
27    {
28        return [
29            'id' => $this->id,
30            'invoices' => $this->invoices,
31            'unit_measurement' => $this->unit_measurement,
32            'created_at' => $this->created_at->toDateString(),
33            'updated_at' => $this->updated_at->toDateString(),
34        ];
35    }
36
37    public static function fromRequest(FormRequest $request): SearchInvoiceItemDTO
38    {
39        return new self([
40            'id' => $request->validated('id'),
41            'invoices' => $request->validated('invoices'),
42            'unit_measurement' => $request->validated('unit_measurement'),
43            'created_at' => $request->validated('created_at'),
44            'updated_at' => $request->validated('updated_at'),
45        ]);
46    }
47}