FilterArrayEntry   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 37
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 4 1
A toArray() 0 10 4
A getValue() 0 3 1
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