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

AllOfCheck::execute()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 6
nop 3
dl 0
loc 18
ccs 10
cts 10
cp 1
crap 4
rs 9.9332
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 AllOfCheck extends CompositeCheck implements CheckInterface
12
{
13
    /**
14
     * {@inheritDoc}
15
     *
16
     * @throws ValidationError
17
     */
18 6
    public function execute($value, array $previousErrors, bool $preventDuplicate = false): void
19
    {
20 6
        $errors = [];
21
22 6
        foreach ($this->rules as $rule) {
23
            try {
24 5
                $rule->validate($value);
25 3
            } catch (ValidationError $e) {
26 3
                $errors[] = $e;
27 3
                break;
28
            }
29
        }
30
31 6
        if (\count($errors) === 0) {
32 3
            return;
33
        }
34
35 3
        throw ValidationError::fromValidationErrors(RuleName::ALL_OF, $value, $errors);
36
    }
37
}
38