Failed Conditions
Push — release-11.5.x ( 71e6eb...3bfdb1 )
by Markus
27:37
created

NumericRangeFacetQueryBuilder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
ccs 0
cts 11
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
*/
17
18
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\NumericRange;
19
20
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetQueryBuilderInterface;
21
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
22
23
class NumericRangeFacetQueryBuilder implements FacetQueryBuilderInterface
24
{
25
    /**
26
     * @param string $facetName
27
     * @param TypoScriptConfiguration $configuration
28
     * @return array
29
     */
30
    public function build(string $facetName, TypoScriptConfiguration $configuration): array
31
    {
32
        $facetParameters = [];
33
        $facetConfiguration = $configuration->getSearchFacetingFacetByName($facetName);
34
35
        $tag = '';
36
        if ((bool)($facetConfiguration['keepAllOptionsOnSelection'] ?? null) === true) {
37
            $tag = '{!ex=' . $facetConfiguration['field'] . '}';
38
        }
39
        $facetParameters['facet.range'][] = $tag . $facetConfiguration['field'];
40
41
        $facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.start'] = $facetConfiguration['numericRange.']['start'];
42
        $facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.end'] = $facetConfiguration['numericRange.']['end'];
43
        $facetParameters['f.' . $facetConfiguration['field'] . '.facet.range.gap'] = $facetConfiguration['numericRange.']['gap'];
44
45
        return $facetParameters;
46
    }
47
}
48