TCheckArrayString   A
last analyzed

Complexity

Total Complexity 5

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 5

2 Methods

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