Failed Conditions
Push — master ( a052b2...ee9c7d )
by Rafael
18:58
created

SortingExpression   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 38
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getForFacet() 0 12 8
A getForJsonFacet() 0 9 3
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017- Timo Hund <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
/**
28
 * Expression for facet sorting
29
 *
30
 * @author Timo Hund <[email protected]>
31
 * @author Jens Jacobsen <[email protected]>
32
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets
33
 */
34
class SortingExpression
35
{
36
    /**
37
     * Return expression for facet sorting
38
     *
39
     * @param string $sorting
40
     * @return string
41
     */
42 77
    public function getForFacet($sorting)
43
    {
44 77
        $noSortingSet = $sorting !== 0 && $sorting !== FALSE && empty($sorting);
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of $sorting (string) and 0 (integer) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
45 77
        $sortingIsCount = $sorting === 'count' || $sorting === 1 || $sorting === '1' || $sorting === TRUE;
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $sorting (string) and 1 (integer) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
46 77
        if ($noSortingSet) {
47 42
            return '';
48 65
        } elseif ($sortingIsCount) {
49 43
            return 'count';
50
        } else {
51 23
            return 'index';
52
        }
53
    }
54
55
    /**
56
     * Return expression for facet sorting combined with direction
57
     *
58
     * @param string $sorting
59
     * @param string $direction
60
     * @return string
61
     */
62 24
    public function getForJsonFacet($sorting, $direction)
63
    {
64 24
        $expression = $this->getForFacet($sorting);
65 24
        $direction = strtolower($direction);
66 24
        if (!empty($direction) && in_array($direction, ['asc', 'desc'])) {
67 16
            $expression .= ' ' . $direction;
68
        }
69 24
        return $expression;
70
    }
71
}
72