RangeFilter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

7 Methods

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