We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 30 |
| Paths | 624 |
| Total Lines | 142 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 190 | public function makeFacetsMenuArray($facets) |
||
| 191 | { |
||
| 192 | $menuArray = []; |
||
| 193 | // Set default value for facet search. |
||
| 194 | $search = [ |
||
| 195 | 'params' => [ |
||
| 196 | 'component' => [ |
||
| 197 | 'facetset' => [ |
||
| 198 | 'facet' => [] |
||
| 199 | ] |
||
| 200 | ] |
||
| 201 | ] |
||
| 202 | ]; |
||
| 203 | |||
| 204 | // Set needed parameters for facet search. |
||
| 205 | if (empty($search['params']['filterquery'])) { |
||
| 206 | $search['params']['filterquery'] = []; |
||
| 207 | } |
||
| 208 | |||
| 209 | $fields = Solr::getFields(); |
||
| 210 | |||
| 211 | // Set search query. |
||
| 212 | $searchParams = $this->searchParams; |
||
| 213 | if ( |
||
| 214 | (!empty($searchParams['fulltext'])) |
||
| 215 | || preg_match('/' . $fields['fulltext'] . ':\((.*)\)/', trim($searchParams['query']), $matches) |
||
| 216 | ) { |
||
| 217 | // If the query already is a fulltext query e.g using the facets |
||
| 218 | $searchParams['query'] = empty($matches[1]) ? $searchParams['query'] : $matches[1]; |
||
| 219 | // Search in fulltext field if applicable. Query must not be empty! |
||
| 220 | if (!empty($this->searchParams['query'])) { |
||
| 221 | $search['query'] = $fields['fulltext'] . ':(' . Solr::escapeQuery(trim($searchParams['query'])) . ')'; |
||
| 222 | } |
||
| 223 | } else { |
||
| 224 | // Retain given search field if valid. |
||
| 225 | if (!empty($searchParams['query'])) { |
||
| 226 | $search['query'] = Solr::escapeQueryKeepField(trim($searchParams['query']), $this->settings['storagePid']); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | // Add extended search query. |
||
| 231 | if ( |
||
| 232 | !empty($searchParams['extQuery']) |
||
| 233 | && is_array($searchParams['extQuery']) |
||
| 234 | ) { |
||
| 235 | $allowedOperators = ['AND', 'OR', 'NOT']; |
||
| 236 | $numberOfExtQueries = count($searchParams['extQuery']); |
||
| 237 | for ($i = 0; $i < $numberOfExtQueries; $i++) { |
||
| 238 | if (!empty($searchParams['extQuery'][$i])) { |
||
| 239 | if ( |
||
| 240 | in_array($searchParams['extOperator'][$i], $allowedOperators) |
||
| 241 | ) { |
||
| 242 | if (!empty($search['query'])) { |
||
| 243 | $search['query'] .= ' ' . $searchParams['extOperator'][$i] . ' '; |
||
| 244 | } |
||
| 245 | $search['query'] .= Indexer::getIndexFieldName($searchParams['extField'][$i], $this->settings['storagePid']) . ':(' . Solr::escapeQuery($searchParams['extQuery'][$i]) . ')'; |
||
| 246 | } |
||
| 247 | } |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 251 | if (isset($this->searchParams['fq']) && is_array($this->searchParams['fq'])) { |
||
| 252 | foreach ($this->searchParams['fq'] as $fq) { |
||
| 253 | $search['params']['filterquery'][]['query'] = $fq; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | // Get applicable facets. |
||
| 258 | $solr = Solr::getInstance($this->settings['solrcore']); |
||
| 259 | if (!$solr->ready) { |
||
| 260 | $this->logger->error('Apache Solr not available'); |
||
| 261 | return []; |
||
| 262 | } |
||
| 263 | |||
| 264 | foreach (array_keys($facets) as $field) { |
||
| 265 | $search['params']['component']['facetset']['facet'][] = [ |
||
| 266 | 'type' => 'field', |
||
| 267 | 'key' => $field, |
||
| 268 | 'field' => $field, |
||
| 269 | 'limit' => $this->settings['limitFacets'], |
||
| 270 | 'sort' => isset($this->settings['sortingFacets']) ? $this->settings['sortingFacets'] : 'count' |
||
| 271 | ]; |
||
| 272 | } |
||
| 273 | |||
| 274 | // Set additional query parameters. |
||
| 275 | $search['params']['start'] = 0; |
||
| 276 | $search['params']['rows'] = 0; |
||
| 277 | // Set query. |
||
| 278 | $search['params']['query'] = $search['query']; |
||
| 279 | // Perform search. |
||
| 280 | $selectQuery = $solr->service->createSelect($search['params']); |
||
| 281 | $results = $solr->service->select($selectQuery); |
||
| 282 | $facet = $results->getFacetSet(); |
||
| 283 | |||
| 284 | $facetCollectionArray = []; |
||
| 285 | |||
| 286 | // replace everything expect numbers and comma |
||
| 287 | $facetCollections = preg_replace('/[^0-9,]/', '', $this->settings['facetCollections']); |
||
| 288 | |||
| 289 | if (!empty($facetCollections)) { |
||
| 290 | $collections = $this->collectionRepository->findCollectionsBySettings(['collections' => $facetCollections]); |
||
| 291 | |||
| 292 | /** @var Collection $collection */ |
||
| 293 | foreach ($collections as $collection) { |
||
| 294 | $facetCollectionArray[] = $collection->getIndexName(); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | // Process results. |
||
| 299 | if ($facet) { |
||
| 300 | foreach ($facet as $field => $values) { |
||
| 301 | $entryArray = []; |
||
| 302 | $entryArray['field'] = substr($field, 0, strpos($field, '_')); |
||
| 303 | $entryArray['count'] = 0; |
||
| 304 | $entryArray['_OVERRIDE_HREF'] = ''; |
||
| 305 | $entryArray['ITEM_STATE'] = 'NO'; |
||
| 306 | // Count number of facet values. |
||
| 307 | $i = 0; |
||
| 308 | foreach ($values as $value => $count) { |
||
| 309 | if ($count > 0) { |
||
| 310 | // check if facet collection configuration exists |
||
| 311 | if (!empty($this->settings['facetCollections'])) { |
||
| 312 | if ($field == "collection_faceting" && !in_array($value, $facetCollectionArray)) { |
||
| 313 | continue; |
||
| 314 | } |
||
| 315 | } |
||
| 316 | $entryArray['count']++; |
||
| 317 | if ($entryArray['ITEM_STATE'] == 'NO') { |
||
| 318 | $entryArray['ITEM_STATE'] = 'IFSUB'; |
||
| 319 | } |
||
| 320 | $entryArray['_SUB_MENU'][] = $this->getFacetsMenuEntry($field, $value, $count, $search, $entryArray['ITEM_STATE']); |
||
| 321 | if (++$i == $this->settings['limit']) { |
||
| 322 | break; |
||
| 323 | } |
||
| 324 | } else { |
||
| 325 | break; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | $menuArray[] = $entryArray; |
||
| 329 | } |
||
| 330 | } |
||
| 331 | return $menuArray; |
||
| 332 | } |
||
| 423 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.