MatchAny::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 3
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 MatchAny
12
 * @package kalanis\kw_rules\Rules
13
 * Check if input matches any subrule
14
 */
15
class MatchAny extends ARule
16
{
17
    use TCheckRules;
18
19 5
    public function validate(IValidate $entry): void
20
    {
21 5
        $last = null;
22 5
        foreach ($this->againstValue as $item) {
23
            /** @var ARule $item */
24
            try {
25 5
                $item->validate($entry);
26 3
                return; // one matched, need no more lookup
27 3
            } catch (RuleException $ex) {
28
                // not good, continue for any other
29 3
                $ex->setPrev($last);
30 3
                $last = $ex;
31
            }
32
        }
33 2
        throw new RuleException($this->errorText, 0, $last);
34
    }
35
}
36