Conditions | 7 |
Paths | 14 |
Total Lines | 66 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | public function parse(SearchResultSet $resultSet, string $facetName, array $facetConfiguration): ?AbstractFacet |
||
53 | { |
||
54 | $response = $resultSet->getResponse(); |
||
55 | $fieldName = $facetConfiguration['field']; |
||
56 | $label = $this->getPlainLabelOrApplyCObject($facetConfiguration); |
||
57 | $optionsFromSolrResponse = $this->getOptionsFromSolrResponse($facetName, $response); |
||
|
|||
58 | $metricsFromSolrResponse = $this->getMetricsFromSolrResponse($facetName, $response); |
||
59 | $optionsFromRequest = $this->getActiveFacetValuesFromRequest($resultSet, $facetName); |
||
60 | $hasOptionsInResponse = !empty($optionsFromSolrResponse); |
||
61 | $hasSelectedOptionsInRequest = count($optionsFromRequest) > 0; |
||
62 | $hasNoOptionsToShow = !$hasOptionsInResponse && !$hasSelectedOptionsInRequest; |
||
63 | $hideEmpty = !$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchFacetingShowEmptyFacetsByName($facetName); |
||
64 | |||
65 | if ($hasNoOptionsToShow && $hideEmpty) { |
||
66 | return null; |
||
67 | } |
||
68 | |||
69 | /** @var $facet OptionsFacet */ |
||
70 | $facet = GeneralUtility::makeInstance( |
||
71 | OptionsFacet::class, |
||
72 | $resultSet, |
||
73 | $facetName, |
||
74 | $fieldName, |
||
75 | $label, |
||
76 | $facetConfiguration |
||
77 | ); |
||
78 | |||
79 | $hasActiveOptions = count($optionsFromRequest) > 0; |
||
80 | $facet->setIsUsed($hasActiveOptions); |
||
81 | $facet->setIsAvailable($hasOptionsInResponse); |
||
82 | |||
83 | $optionsToCreate = $this->getMergedFacetValueFromSearchRequestAndSolrResponse($optionsFromSolrResponse, $optionsFromRequest); |
||
84 | foreach ($optionsToCreate as $optionsValue => $count) { |
||
85 | if ($this->getIsExcludedFacetValue($optionsValue, $facetConfiguration)) { |
||
86 | continue; |
||
87 | } |
||
88 | |||
89 | $isOptionsActive = in_array($optionsValue, $optionsFromRequest); |
||
90 | $label = $this->getLabelFromRenderingInstructions($optionsValue, $count, $facetName, $facetConfiguration); |
||
91 | $facet->addOption( |
||
92 | GeneralUtility::makeInstance( |
||
93 | Option::class, |
||
94 | $facet, |
||
95 | $label, |
||
96 | $optionsValue, |
||
97 | $count, |
||
98 | $isOptionsActive, |
||
99 | ($metricsFromSolrResponse[$optionsValue] ?? []) |
||
100 | ) |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | // after all options have been created we apply a manualSortOrder if configured |
||
105 | // the sortBy (lex,..) is done by the solr server and triggered by the query, therefore it does not |
||
106 | // need to be handled in the frontend. |
||
107 | $this->applyManualSortOrder($facet, $facetConfiguration); |
||
108 | $this->applyReverseOrder($facet, $facetConfiguration); |
||
109 | |||
110 | if (isset($this->eventDispatcher)) { |
||
111 | /* @var AfterFacetParsedEvent $afterFacetParsedEvent */ |
||
112 | $afterFacetParsedEvent = $this->eventDispatcher |
||
113 | ->dispatch(new AfterFacetParsedEvent($facet, $facetConfiguration)); |
||
114 | $facet = $afterFacetParsedEvent->getFacet(); |
||
115 | } |
||
116 | |||
117 | return $facet; |
||
118 | } |
||
167 |