TCheckRules   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkValue() 0 6 2
A checkRule() 0 9 4
1
<?php
2
3
namespace kalanis\kw_rules\Rules;
4
5
6
use kalanis\kw_rules\Exceptions\RuleException;
7
8
9
/**
10
 * trait TCheckRules
11
 * @package kalanis\kw_rules\Rules
12
 * Check original values as set of rules
13
 */
14
trait TCheckRules
15
{
16
    use TRule;
17
18
    /**
19
     * @param mixed|null $againstValue
20
     * @throws RuleException
21
     * @return array<ARule|File\AFileRule>
22
     */
23 12
    protected function checkValue($againstValue)
24
    {
25 12
        if (!is_array($againstValue)) {
26 1
            throw new RuleException('No array found. Need set matching rules!');
27
        }
28 11
        return array_map([$this, 'checkRule'], $againstValue);
29
    }
30
31
    /**
32
     * @param mixed|null $singleRule
33
     * @throws RuleException
34
     * @return ARule|File\AFileRule
35
     */
36 11
    protected function checkRule($singleRule)
37
    {
38 11
        if (!is_object($singleRule)) {
39 1
            throw new RuleException('Input is not an object.');
40
        }
41 10
        if (! ( ($singleRule instanceof ARule) || ($singleRule instanceof File\AFileRule) ) ) {
42 1
            throw new RuleException(sprintf('Input %s is not instance of ARule or AFileRule.', get_class($singleRule)));
43
        }
44 9
        return $singleRule;
45
    }
46
}
47