| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 OptionsFacetParser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class OptionsFacetParser extends AbstractFacetParser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @param SearchResultSet $resultSet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param string $facetName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param array $facetConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @return OptionsFacet|null | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |     public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration) | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |         $response = $resultSet->getResponse(); | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |         $fieldName = $facetConfiguration['field']; | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |         $label = $this->getPlainLabelOrApplyCObject($facetConfiguration); | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |         $optionsFromSolrResponse = isset($response->facet_counts->facet_fields->{$fieldName}) ? get_object_vars($response->facet_counts->facet_fields->{$fieldName}) : []; | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |         $optionsFromRequest = $this->getActiveFacetValuesFromRequest($resultSet, $facetName); | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |         $hasOptionsInResponse = !empty($optionsFromSolrResponse); | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |         $hasSelectedOptionsInRequest = count($optionsFromRequest) > 0; | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |         $hasNoOptionsToShow = !$hasOptionsInResponse && !$hasSelectedOptionsInRequest; | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |         $hideEmpty = !$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchFacetingShowEmptyFacetsByName($facetName); | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |         if ($hasNoOptionsToShow && $hideEmpty) { | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |             return null; | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         /** @var $facet OptionsFacet */ | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         $facet = $this->objectManager->get( | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |             OptionsFacet::class, | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |             $resultSet, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |             $facetName, | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |             $fieldName, | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |             $label, | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |             $facetConfiguration | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         ); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |         $hasActiveOptions = count($optionsFromRequest) > 0; | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         $facet->setIsUsed($hasActiveOptions); | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |         $facet->setIsAvailable($hasOptionsInResponse); | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |         $optionsToCreate = $this->getMergedFacetValueFromSearchRequestAndSolrResponse($optionsFromSolrResponse, $optionsFromRequest); | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |         foreach ($optionsToCreate as $optionsValue => $count) { | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |             $isOptionsActive = in_array($optionsValue, $optionsFromRequest); | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |             $label = $this->getLabelFromRenderingInstructions($optionsValue, $count, $facetName, $facetConfiguration); | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |             $facet->addOption(new Option($facet, $label, $optionsValue, $count, $isOptionsActive)); | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |         // after all options have been created we apply a manualSortOrder if configured | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         // the sortBy (lex,..) is done by the solr server and triggered by the query, therefore it does not | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         // need to be handled in the frontend. | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |         $facet = $this->applyManualSortOrder($facet, $facetConfiguration); | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |         $facet = $this->applyReverseOrder($facet, $facetConfiguration); | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |         return $facet; | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  | 
            
                        
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.