Passed
Push — master ( 203e1d...831cab )
by Timo
27:25
created

AbstractFacet   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 221
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 84.09%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 0
dl 0
loc 221
ccs 37
cts 44
cp 0.8409
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getName() 0 4 1
A getField() 0 4 1
A setLabel() 0 4 1
A getLabel() 0 4 1
A setIsAvailable() 0 4 1
A getIsAvailable() 0 4 1
A setIsUsed() 0 4 1
A getIsUsed() 0 4 1
A getType() 0 4 1
A getResultSet() 0 4 1
A getConfiguration() 0 4 1
A getPartialName() 0 4 1
A getGroupName() 0 4 2
A getIncludeInAvailableFacets() 0 4 1
A getIncludeInUsedFacets() 0 5 1
getAllFacetItems() 0 1 ?
A getFacetSettingOrDefaultValue() 0 8 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
17
18
/**
19
 * Value object that represent a options facet.
20
 *
21
 * @author Frans Saris <[email protected]>
22
 * @author Timo Hund <[email protected]>
23
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionsFacet
24
 */
25
abstract class AbstractFacet
26
{
27
    const TYPE_ABSTRACT = 'abstract';
28
29
    /**
30
     * String
31
     * @var string
32
     */
33
    protected static $type = self::TYPE_ABSTRACT;
34
35
    /**
36
     * The resultSet where this facet belongs to.
37
     *
38
     * @var SearchResultSet
39
     */
40
    protected $resultSet = null;
41
42
    /**
43
     * @var string
44
     */
45
    protected $name;
46
47
    /**
48
     * @var string
49
     */
50
    protected $field;
51
52
    /**
53
     * @var string
54
     */
55
    protected $label;
56
57
    /**
58
     * @var []
59
     */
60
    protected $configuration;
61
62
    /**
63
     * @var boolean
64
     */
65
    protected $isAvailable = false;
66
67
    /**
68
     * @var bool
69
     */
70
    protected $isUsed = false;
71
72
    /**
73
     * AbstractFacet constructor.
74
     *
75
     * @param SearchResultSet $resultSet
76
     * @param string $name
77
     * @param string $field
78
     * @param string $label
79
     * @param array $configuration Facet configuration passed from typoscript
80
     */
81 80
    public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = [])
82
    {
83 80
        $this->resultSet = $resultSet;
84 80
        $this->name = $name;
85 80
        $this->field = $field;
86 80
        $this->label = $label;
87 80
        $this->configuration = $configuration;
88 80
    }
89
90
    /**
91
     * Get name
92
     *
93
     * @return string
94
     */
95 52
    public function getName()
96
    {
97 52
        return $this->name;
98
    }
99
100
    /**
101
     * Get solr field name
102
     *
103
     * @return string
104
     */
105
    public function getField()
106
    {
107
        return $this->field;
108
    }
109
110
    /**
111
     * @param string $label
112
     */
113
    public function setLabel($label)
114
    {
115
        $this->label = $label;
116
    }
117
118
    /**
119
     * @return string
120
     */
121 24
    public function getLabel()
122
    {
123 24
        return $this->label;
124
    }
125
126
    /**
127
     * @param boolean $isAvailable
128
     */
129 54
    public function setIsAvailable($isAvailable)
130
    {
131 54
        $this->isAvailable = $isAvailable;
132 54
    }
133
134
    /**
135
     * @return boolean
136
     */
137 23
    public function getIsAvailable()
138
    {
139 23
        return $this->isAvailable;
140
    }
141
142
    /**
143
     * @param boolean $isUsed
144
     */
145 54
    public function setIsUsed($isUsed)
146
    {
147 54
        $this->isUsed = $isUsed;
148 54
    }
149
150
    /**
151
     * @return boolean
152
     */
153 29
    public function getIsUsed()
154
    {
155 29
        return $this->isUsed;
156
    }
157
158
    /**
159
     * @return string
160
     */
161 21
    public function getType()
162
    {
163 21
        return static::$type;
164
    }
165
166
    /**
167
     * @return SearchResultSet
168
     */
169 23
    public function getResultSet()
170
    {
171 23
        return $this->resultSet;
172
    }
173
174
    /**
175
     * Get configuration
176
     *
177
     * @return mixed
178
     */
179 2
    public function getConfiguration()
180
    {
181 2
        return $this->configuration;
182
    }
183
184
    /**
185
     * Get facet partial name used for rendering the facet
186
     *
187
     * @return string
188
     */
189
    public function getPartialName()
190
    {
191
        return 'Default';
192
    }
193
194
    /**
195
     * @return string
196
     */
197 24
    public function getGroupName()
198
    {
199 24
        return isset($this->configuration['groupName']) ? $this->configuration['groupName'] : 'main';
200
    }
201
202
    /**
203
     * Indicates if this facet should ne included in the available facets. When nothing is configured,
204
     * the method return TRUE.
205
     *
206
     * @return boolean
207
     */
208 28
    public function getIncludeInAvailableFacets()
209
    {
210 28
        return ((int)$this->getFacetSettingOrDefaultValue('includeInAvailableFacets', 1)) === 1;
211
    }
212
213
    /**
214
     * Indicates if this facets should be included in the used facets. When nothing is configured,
215
     * the methods returns true.
216
     *
217
     * @return boolean
218
     */
219 4
    public function getIncludeInUsedFacets()
220
    {
221
222 4
        return ((int) $this->getFacetSettingOrDefaultValue('includeInUsedFacets', 1)) === 1;
223
    }
224
225
    /**
226
     * The implementation of this method should return a "flatten" collection of all items.
227
     *
228
     * @return AbstractFacetItemCollection
229
     */
230
    abstract public function getAllFacetItems();
231
232
    /**
233
     * @param string $key
234
     * @param mixed $defaultValue
235
     * @return mixed
236
     */
237 29
    protected function getFacetSettingOrDefaultValue($key, $defaultValue)
238
    {
239 29
        if (!isset($this->configuration[$key])) {
240 22
            return $defaultValue;
241
        }
242
243 7
        return ((string)$this->configuration[$key]);
244
    }
245
}
246