TCheckArrayRange::checkRule()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace kalanis\kw_rules\Rules;
4
5
6
use kalanis\kw_rules\Exceptions\RuleException;
7
8
9
/**
10
 * trait TCheckArrayRange
11
 * @package kalanis\kw_rules\Rules
12
 * Check original values as array of ranges
13
 */
14
trait TCheckArrayRange
15
{
16
    use TRule;
17
18
    /**
19
     * @param mixed|null $againstValue
20
     * @throws RuleException
21
     * @return array<array<int>>
22
     */
23 8
    protected function checkValue($againstValue)
24
    {
25 8
        if (!is_array($againstValue)) {
26 1
            throw new RuleException('No array found. Need set input as array!');
27
        }
28 7
        return array_map([$this, 'checkRule'], $againstValue);
29
    }
30
31
    /**
32
     * @param mixed|null $againstValue
33
     * @throws RuleException
34
     * @return array<int>
35
     */
36 7
    protected function checkRule($againstValue): array
37
    {
38 7
        if (!is_array($againstValue)) {
39 1
            throw new RuleException('No array found. Need set both values to compare!');
40
        }
41 6
        return array_map('intval', $againstValue);
42
    }
43
}
44