1 | <?php |
||
27 | abstract class AbstractRangeFacetParser extends AbstractFacetParser |
||
28 | { |
||
29 | /** |
||
30 | * @param SearchResultSet $resultSet |
||
31 | * @param string $facetName |
||
32 | * @param array $facetConfiguration |
||
33 | * @param string $facetClass |
||
34 | * @param string $facetItemClass |
||
35 | * @param string $facetRangeCountClass |
||
36 | * @return AbstractRangeFacet|null |
||
37 | */ |
||
38 | 6 | protected function getParsedFacet(SearchResultSet $resultSet, $facetName, array $facetConfiguration, $facetClass, $facetItemClass, $facetRangeCountClass) |
|
39 | { |
||
40 | 6 | $fieldName = $facetConfiguration['field']; |
|
41 | 6 | $label = $this->getPlainLabelOrApplyCObject($facetConfiguration); |
|
42 | 6 | $activeValue = $this->getActiveFacetValuesFromRequest($resultSet, $facetName); |
|
43 | 6 | $response = $resultSet->getResponse(); |
|
44 | 6 | $valuesFromResponse = isset($response->facet_counts->facet_ranges->{$fieldName}) ? get_object_vars($response->facet_counts->facet_ranges->{$fieldName}) : []; |
|
45 | |||
46 | 6 | $facet = $this->objectManager->get( |
|
47 | $facetClass, |
||
48 | $resultSet, |
||
|
|||
49 | $facetName, |
||
50 | $fieldName, |
||
51 | $label, |
||
52 | 6 | $facetConfiguration |
|
53 | ); |
||
54 | |||
55 | 6 | $facet->setIsAvailable(count($valuesFromResponse) > 0); |
|
56 | 6 | $facet->setIsUsed(count($activeValue) > 0); |
|
57 | |||
58 | 6 | if (is_array($valuesFromResponse)) { |
|
59 | 6 | $rangeCounts = []; |
|
60 | 6 | $allCount = 0; |
|
61 | |||
62 | 6 | $countsFromResponse = isset($valuesFromResponse['counts']) ? get_object_vars($valuesFromResponse['counts']) : []; |
|
63 | 6 | foreach ($countsFromResponse as $rangeCountValue => $count) { |
|
64 | 5 | $rangeCountValue = $this->parseResponseValue($rangeCountValue); |
|
65 | 5 | $rangeCount = new $facetRangeCountClass($rangeCountValue, $count); |
|
66 | 5 | $rangeCounts[] = $rangeCount; |
|
67 | 5 | $allCount += $count; |
|
68 | } |
||
69 | |||
70 | 6 | $fromInResponse = $this->parseResponseValue($valuesFromResponse['start']); |
|
71 | 6 | $toInResponse = $this->parseResponseValue($valuesFromResponse['end']); |
|
72 | |||
73 | 6 | if (preg_match('/(-?\d*?)-(-?\d*)/', $activeValue[0], $rawValues) == 1) { |
|
74 | 5 | $rawFrom = $rawValues[1]; |
|
75 | 5 | $rawTo = $rawValues[2]; |
|
76 | } else { |
||
77 | 1 | $rawFrom = 0; |
|
78 | 1 | $rawTo = 0; |
|
79 | } |
||
80 | |||
81 | 6 | $from = $this->parseRequestValue($rawFrom); |
|
82 | 6 | $to = $this->parseRequestValue($rawTo); |
|
83 | |||
84 | 6 | $type = isset($facetConfiguration['type']) ? $facetConfiguration['type'] : 'numericRange'; |
|
85 | 6 | $gap = isset($facetConfiguration[$type . '.']['gap']) ? $facetConfiguration[$type . '.']['gap'] : 1; |
|
86 | |||
87 | 6 | $range = new $facetItemClass($facet, $from, $to, $fromInResponse, $toInResponse, $gap, $allCount, $rangeCounts, true); |
|
88 | 6 | $facet->setRange($range); |
|
89 | } |
||
90 | |||
91 | 6 | return $facet; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param string $requestValue |
||
96 | * @return mixed |
||
97 | */ |
||
98 | abstract protected function parseRequestValue($requestValue); |
||
99 | |||
100 | /** |
||
101 | * @param string $responseValue |
||
102 | * @return mixed |
||
103 | */ |
||
104 | abstract protected function parseResponseValue($responseValue); |
||
105 | } |
||
106 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.