MatchAll::validate()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
1
<?php
2
3
namespace kalanis\kw_rules\Rules;
4
5
6
use kalanis\kw_rules\Interfaces\IValidate;
7
use kalanis\kw_rules\Exceptions\RuleException;
8
9
10
/**
11
 * Class MatchAll
12
 * @package kalanis\kw_rules\Rules
13
 * Check if input matches all subrules
14
 */
15
class MatchAll extends ARule
16
{
17
    use TCheckRules;
18
19 4
    public function validate(IValidate $entry): void
20
    {
21 4
        $last = null;
22 4
        foreach ($this->againstValue as $item) {
23
            /** @var ARule $item */
24
            try {
25 4
                $item->validate($entry);
26 3
            } catch (RuleException $ex) {
27
                // not good, continue for any other
28 3
                $ex->setPrev($last);
29 3
                $last = $ex;
30
            }
31
        }
32 4
        if (!empty($last)) {
33
            // it will die when something has been found
34 3
            throw new RuleException($this->errorText, 0, $last);
35
        }
36 1
    }
37
}
38