Passed
Push — main ( f7f95e...c4cb1e )
by Breno
02:19
created

ValidationExceptionTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 13
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrors() 0 3 1
A addError() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Exception;
5
6
use BrenoRoosevelt\Validation\Error;
7
use BrenoRoosevelt\Validation\ErrorMessage;
8
9
trait ValidationExceptionTrait
10
{
11
    /** @var Error[] */
12
    protected array $errors = [];
13
14
    public function addError(string $message, ?string $field = null): void
15
    {
16
        $this->errors[] = new ErrorMessage($message, $field);
17
    }
18
19
    public function getErrors(): array
20
    {
21
        return $this->errors;
22
    }
23
}
24