Passed
Push — master ( d3853d...011878 )
by Smoren
02:21
created

OrRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 24 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Rules;
6
7
use Smoren\Validator\Exceptions\ValidationSuccessException;
8
use Smoren\Validator\Exceptions\ValidationError;
9
use Smoren\Validator\Interfaces\ExecutionResultInterface;
10
use Smoren\Validator\Structs\ExecutionResult;
11
12
class OrRule extends CompositeRule
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17 9
    protected function execute($value): ExecutionResultInterface
18
    {
19 9
        $result = parent::execute($value);
20 7
        if ($result->areChecksSufficient()) {
21 2
            return $result;
22
        }
23
24 7
        $result = new ExecutionResult(false);
25
26 7
        $errors = [];
27 7
        foreach ($this->rules as $rule) {
28
            try {
29 6
                $rule->validate($value);
30 3
                return $result;
31 6
            } catch (ValidationError $e) {
32 6
                $errors[] = $e;
33
            }
34
        }
35
36 4
        if (\count($errors) === 0) {
37 1
            return $result;
38
        }
39
40 3
        throw ValidationError::fromValidationErrors($value, $errors);
41
    }
42
}
43