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

NumericRange::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
ccs 0
cts 11
cp 0
rs 9.9332
c 0
b 0
f 0
cc 3
nc 2
nop 9
crap 12

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\RangeBased\AbstractRangeFacetItem;
21
22
/**
23
 * Value object that represent an option of a numeric range facet.
24
 *
25
 * @author Frans Saris <[email protected]>
26
 * @author Timo Hund <[email protected]>
27
 */
28
class NumericRange extends AbstractRangeFacetItem
29
{
30
    /**
31
     * @var float|null
32
     */
33
    protected ?float $startRequested = null;
34
35
    /**
36
     * @var float|null
37
     */
38
    protected ?float $endRequested = null;
39
40
    /**
41
     * @var float|null
42
     */
43
    protected ?float $startInResponse = null;
44
45
    /**
46
     * @var float|null
47
     */
48
    protected ?float $endInResponse = null;
49
50
    /**
51
     * @param NumericRangeFacet $facet
52
     * @param float|null $startRequested
53
     * @param float|null $endRequested
54
     * @param float|null $startInResponse
55
     * @param float|null $endInResponse
56
     * @param string $gap
57
     * @param int $documentCount
58
     * @param array|null $rangeCounts
59
     * @param bool $selected
60
     */
61
    public function __construct(
62
        NumericRangeFacet $facet,
63
        ?float $startRequested = null,
64
        ?float $endRequested = null,
65
        ?float $startInResponse = null,
66
        ?float $endInResponse = null,
67
        string $gap = '',
68
        int $documentCount = 0,
69
        ?array $rangeCounts = [],
70
        bool $selected = false
71
    ) {
72
        $this->startInResponse = $startInResponse;
73
        $this->endInResponse = $endInResponse;
74
        $this->startRequested = $startRequested;
75
        $this->endRequested = $endRequested;
76
        $this->rangeCounts = $rangeCounts;
77
        $this->gap = $gap;
78
79
        $label = '';
80
        if ($startRequested !== null && $endRequested !== null) {
81
            $label = $this->getRangeString();
82
        }
83
84
        parent::__construct($facet, $label, $documentCount, $selected);
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    protected function getRangeString(): string
91
    {
92
        return $this->startRequested . '-' . $this->endRequested;
93
    }
94
95
    /**
96
     * Retrieves the end date that was requested by the user for this facet.
97
     *
98
     * @return float|null
99
     */
100
    public function getEndRequested(): ?float
101
    {
102
        return $this->endRequested;
103
    }
104
105
    /**
106
     * Retrieves the start date that was requested by the used for the facet.
107
     *
108
     * @return float|null
109
     */
110
    public function getStartRequested(): ?float
111
    {
112
        return $this->startRequested;
113
    }
114
115
    /**
116
     * Retrieves the end date that was received from solr for this facet.
117
     *
118
     * @return float|null
119
     */
120
    public function getEndInResponse(): ?float
121
    {
122
        return $this->endInResponse;
123
    }
124
125
    /**
126
     * Retrieves the start date that was received from solr for this facet.
127
     *
128
     * @return float|null
129
     */
130
    public function getStartInResponse(): ?float
131
    {
132
        return $this->startInResponse;
133
    }
134
}
135