Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
63.64% covered (warning)
63.64%
14 / 22
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
StoreInvoiceActivityLogDTO
63.64% covered (warning)
63.64%
14 / 22
66.67% covered (warning)
66.67%
2 / 3
3.43
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 fromRequest
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\Invoice\DTOs;
4
5use App\Models\Invoice\Invoice;
6use App\Models\User;
7use Carbon\Carbon;
8use Domain\Invoice\Enums\InvoiceActivetyLogOperationEnum;
9use Domain\Shared\Interfaces\DataTransferObjectInterface;
10use Illuminate\Foundation\Http\FormRequest;
11
12readonly final class StoreInvoiceActivityLogDTO implements DataTransferObjectInterface
13{
14    public ?int $entity_id;
15    public string $entity_type;
16    public InvoiceActivetyLogOperationEnum $operation;
17    public User $user;
18    public string $detail;
19    public string $observation;
20
21    public function __construct(array $args)
22    {
23        $this->entity_id   = $args['entity_id'] ?? null;
24        $this->entity_type = $args['entity_type'];
25        $this->operation   = $args['operation'];
26        $this->user        = $args['user'];
27        $this->detail      = $args['detail'];
28        $this->observation = $args['observation'];
29    }
30
31    public function toArray(): array
32    {
33        return [
34            'entity_id'   => $this->entity_id,
35            'entity_type' => $this->entity_type,
36            'operation'   => $this->operation->value,
37            'user'        => $this->user,
38            'detail'      => $this->detail,
39            'observation' => $this->observation,
40        ];
41    }
42
43    public static function fromRequest(FormRequest $request): StoreInvoiceActivityLogDTO
44    {
45        return new self([
46            'entity_id'   => $request->validated('entity_id'),
47            'entity_type' => $request->validated('entity_type'),
48            'operation'   => InvoiceActivetyLogOperationEnum::tryFrom($request->validated('suppliers')),
49            'user'        => $request->validated('user'),
50            'detail'      => $request->validated('detail'),
51            'observation' => $request->validated('observation'),
52        ]);
53    }
54}