SimpleFilter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createFromValue() 0 4 1
A getField() 0 4 1
A getValue() 0 4 1
A getFilterValue() 0 4 1
A getType() 0 4 1
A jsonSerialize() 0 18 2
1
<?php
2
3
namespace BenTools\OpenCubes\Component\Filter\Model;
4
5
use function BenTools\OpenCubes\stringify_uri;
6
7
final class SimpleFilter extends Filter
8
{
9
    /**
10
     * @var string
11
     */
12
    private $field;
13
14
    /**
15
     * @var FilterValue|null
16
     */
17
    private $value;
18
19
    /**
20
     * SimpleFilter constructor.
21
     * @param string           $field
22
     * @param FilterValue|null $value
23
     */
24
    public function __construct(string $field, FilterValue $value = null)
25
    {
26
        $this->field = $field;
27
        $this->value = $value;
28
    }
29
30
    /**
31
     * @param string $field
32
     * @param        $value
33
     * @return SimpleFilter
34
     */
35
    public static function createFromValue(string $field, $value): self
36
    {
37
        return new self($field, new FilterValue($value));
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function getField(): string
44
    {
45
        return $this->field;
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51
    public function getValue()
52
    {
53
        return $this->value->getValue();
54
    }
55
56
    /**
57
     * @return FilterValue|null
58
     */
59
    public function getFilterValue(): ?FilterValue
60
    {
61
        return $this->value;
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function getType(): string
68
    {
69
        return 'simple';
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function jsonSerialize(): array
76
    {
77
        $output = [
78
            'type'       => $this->getType(),
79
            'field'      => $this->getField(),
80
            'value'      => $this->getFilterValue(),
81
            'is_applied' => $this->isApplied(),
82
            'is_negated' => $this->isNegated(),
83
        ];
84
85
        if ($this->isApplied()) {
86
            $output['unset_link'] = stringify_uri($this->getToggleUri());
87
        } else {
88
            $output['link'] = stringify_uri($this->getToggleUri());
89
        }
90
91
        return $output;
92
    }
93
}
94