Passed
Push — master ( 1b59d3...daf3c8 )
by Smoren
02:18
created

AnyOfCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Checks;
6
7
use Smoren\Validator\Exceptions\ValidationError;
8
use Smoren\Validator\Interfaces\CheckInterface;
9
use Smoren\Validator\Structs\RuleName;
10
11
class AnyOfCheck extends CompositeCheck implements CheckInterface
12
{
13
    /**
14
     * {@inheritDoc}
15
     *
16
     * @throws ValidationError
17
     */
18 7
    public function execute($value, array $previousErrors, bool $preventDuplicate = false): void
19
    {
20 7
        $errors = [];
21
22 7
        foreach ($this->rules as $rule) {
23
            try {
24 6
                $rule->validate($value);
25 3
                return;
26 6
            } catch (ValidationError $e) {
27 6
                $errors[] = $e;
28
            }
29
        }
30
31 4
        if (\count($errors) === 0) {
32 1
            return;
33
        }
34
35 3
        throw ValidationError::fromValidationErrors(RuleName::ANY_OF, $value, $errors);
36
    }
37
}
38