GuardForValidation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 11
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateOrFail() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation;
5
6
trait GuardForValidation
7
{
8
    public function validateOrFail($input, array $context = [], string $message = 'Validation errors'): void
9
    {
10
        if (! $this instanceof Validation) {
11
            return;
12
        }
13
14
        $violations = $this->validate($input, $context);
15
        if (!$violations->isOk()) {
16
            throw new ValidationException($violations, $message);
17
        }
18
    }
19
}
20