AllOfCheck::__invoke()   A
last analyzed

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 0
Metric Value
cc 4
eloc 10
nc 6
nop 3
dl 0
loc 18
ccs 10
cts 10
cp 1
crap 4
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Checks;
6
7
use Smoren\Validator\Exceptions\CompositeCheckError;
8
use Smoren\Validator\Exceptions\ValidationError;
9
use Smoren\Validator\Interfaces\CheckInterface;
10
use Smoren\Validator\Structs\CheckName;
11
12
final class AllOfCheck extends CompositeCheck implements CheckInterface
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17 12
    public function __invoke($value, array $previousErrors, bool $preventDuplicate = false): void
18
    {
19 12
        $errors = [];
20
21 12
        foreach ($this->rules as $rule) {
22
            try {
23 10
                $rule->validate($value);
24 6
            } catch (ValidationError $e) {
25 6
                $errors[] = $e;
26 6
                break;
27
            }
28
        }
29
30 12
        if (\count($errors) === 0) {
31 6
            return;
32
        }
33
34 6
        throw new CompositeCheckError(CheckName::ALL_OF, $value, $errors);
35
    }
36
}
37