FilterArrayEntry::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
crap 4
1
<?php
2
3
namespace kalanis\kw_filter;
4
5
6
/**
7
 * Class FilterArrayEntry
8
 * @package kalanis\kw_filter
9
 * Filtering by array, not by just simple compare
10
 */
11
class FilterArrayEntry extends AFilterEntry
12
{
13
    protected static $relations = [
14
        self::RELATION_IN,
15
        self::RELATION_NOT_IN,
16
    ];
17
18
    protected $relation = self::RELATION_IN;
19
    /** @var string[] */
20
    protected $value = [];
21
22 6
    public function setValue($value): Interfaces\IFilterEntry
23
    {
24 6
        $this->value = array_map('strval', $this->toArray($value));
25 6
        return $this;
26
    }
27
28
    /**
29
     * @param string|string[]|Interfaces\IFilterEntry $value
30
     * @return string[]
31
     */
32 6
    protected function toArray($value): array
33
    {
34 6
        if (is_object($value)) {
35 1
            return [strval($value)];
36 5
        } elseif (is_numeric($value)) {
37 1
            return [strval($value)];
38 4
        } elseif (is_scalar($value)) {
39 2
            return [strval($value)];
40
        } else {
41 2
            return $value;
42
        }
43
    }
44
45 7
    public function getValue()
46
    {
47 7
        return $this->value;
48
    }
49
}
50