Passed
Push — master ( 9129d6...9f4504 )
by Smoren
02:40
created

OrRule::validate()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.9666
cc 4
nc 5
nop 1
crap 20
1
<?php
2
3
namespace Smoren\Validator\Rules;
4
5
use Smoren\Validator\Exceptions\ValidationError;
6
7
class OrRule extends CompositeRule
8
{
9
    public function validate($value): void
10
    {
11
        $errors = [];
12
        foreach ($this->rules as $rule) {
13
            try {
14
                $rule->validate($value);
15
                return;
16
            } catch (ValidationError $e) {
17
                $errors[] = $e;
18
            }
19
        }
20
21
        if (\count($errors) === 0) {
22
            return;
23
        }
24
    }
25
}