| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Class NumericRangeFacetParser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author Frans Saris <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @author Timo Hund <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |     protected function getParsedFacet(SearchResultSet $resultSet, $facetName, array $facetConfiguration, $facetClass, $facetItemClass, $facetRangeCountClass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $fieldName = $facetConfiguration['field']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $label = $this->getPlainLabelOrApplyCObject($facetConfiguration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $activeValue = $this->getActiveFacetValuesFromRequest($resultSet, $facetName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $response = $resultSet->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $valuesFromResponse = isset($response->facet_counts->facet_ranges->{$fieldName}) ? get_object_vars($response->facet_counts->facet_ranges->{$fieldName}) : []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $facet = $this->objectManager->get( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $facetClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $resultSet, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $facetName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $fieldName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $label, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             $facetConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $facet->setIsAvailable(count($valuesFromResponse) > 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $facet->setIsUsed(count($activeValue) > 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         if (is_array($valuesFromResponse)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             $rangeCounts = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $allCount = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $countsFromResponse = isset($valuesFromResponse['counts']) ? get_object_vars($valuesFromResponse['counts']) : []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             foreach ($countsFromResponse as $rangeCountValue => $count) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 $rangeCountValue = $this->parseResponseValue($rangeCountValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 $rangeCount = new $facetRangeCountClass($rangeCountValue, $count); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 $rangeCounts[] = $rangeCount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 $allCount += $count; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             $fromInResponse = $this->parseResponseValue($valuesFromResponse['start']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $toInResponse = $this->parseResponseValue($valuesFromResponse['end']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             if (preg_match('/(-?\d*?)-(-?\d*)/', $activeValue[0], $rawValues) == 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 $rawFrom = $rawValues[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 $rawTo = $rawValues[2]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 $rawFrom = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 $rawTo = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $from = $this->parseRequestValue($rawFrom); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             $to = $this->parseRequestValue($rawTo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $type = isset($facetConfiguration['type']) ? $facetConfiguration['type'] : 'numericRange'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $gap = isset($facetConfiguration[$type . '.']['gap']) ? $facetConfiguration[$type . '.']['gap'] : 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             $range = new $facetItemClass($facet, $from, $to, $fromInResponse, $toInResponse, $gap, $allCount, $rangeCounts, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             $facet->setRange($range); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         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
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.