MatchAny   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 3
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