TCheckArrayString::checkRule()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
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 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