FilterValue::isApplied()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BenTools\OpenCubes\Component\Filter\Model;
4
5
use function BenTools\OpenCubes\stringify_uri;
6
use Psr\Http\Message\UriInterface;
7
8
final class FilterValue implements \JsonSerializable
9
{
10
    /**
11
     * @var string
12
     */
13
    private $key;
14
15
    /**
16
     * @var mixed
17
     */
18
    private $value;
19
20
    /**
21
     * @var bool
22
     */
23
    private $applied;
24
25
    /**
26
     * @var int
27
     */
28
    private $count;
29
30
    /**
31
     * @var UriInterface
32
     */
33
    private $toggleUri;
34
35
    /**
36
     * FilterValue constructor.
37
     */
38
    public function __construct(string $key, $value = null, bool $applied = true, ?int $count = null, ?UriInterface $toggleUri = null)
39
    {
40
        $this->key = $key;
41
        $this->value = $value ?? (func_num_args() === 1 ? $key : $value);
42
        $this->applied = $applied;
43
        $this->count = $count;
44
        $this->toggleUri = $toggleUri;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getKey(): string
51
    {
52
        return $this->key;
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58
    public function getValue()
59
    {
60
        return $this->value;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isApplied(): bool
67
    {
68
        return $this->applied;
69
    }
70
71
    /**
72
     * @return int
73
     */
74
    public function getCount(): ?int
75
    {
76
        return $this->count;
77
    }
78
79
    /**
80
     * @return UriInterface
81
     */
82
    public function getToggleUri(): ?UriInterface
83
    {
84
        return $this->toggleUri;
85
    }
86
87
    /**
88
     * @param bool $applied
89
     */
90
    public function setApplied(bool $applied): void
91
    {
92
        $this->applied = $applied;
93
    }
94
95
    /**
96
     * @param int $count
97
     */
98
    public function setCount(int $count): void
99
    {
100
        $this->count = $count;
101
    }
102
103
    /**
104
     * @param UriInterface $toggleUri
105
     */
106
    public function setToggleUri(UriInterface $toggleUri): void
107
    {
108
        $this->toggleUri = $toggleUri;
109
    }
110
111
    /**
112
     * @inheritDoc
113
     */
114
    public function jsonSerialize()
115
    {
116
        $output = [
117
            'key'        => $this->getKey(),
118
            'value'      => $this->getValue(),
119
            'is_applied' => $this->isApplied(),
120
            'count'      => $this->getCount(),
121
        ];
122
123
        if ($this->isApplied()) {
124
            $output['unset_link'] = stringify_uri($this->getToggleUri());
125
        } else {
126
            $output['link'] = stringify_uri($this->getToggleUri());
127
        }
128
129
        return $output;
130
    }
131
}
132