| Conditions | 48 |
| Paths | 772 |
| Total Lines | 285 |
| Code Lines | 111 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 437 | public function main($content, $conf) { |
||
| 438 | |||
| 439 | $this->init($conf); |
||
| 440 | |||
| 441 | // Disable caching for this plugin. |
||
| 442 | $this->setCache(FALSE); |
||
| 443 | |||
| 444 | // Quit without doing anything if required variables are not set. |
||
| 445 | if (empty($this->conf['solrcore'])) { |
||
| 446 | |||
| 447 | if (TYPO3_DLOG) { |
||
| 448 | |||
| 449 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->main('.$content.', [data])] Incomplete plugin configuration', $this->extKey, SYSLOG_SEVERITY_WARNING, $conf); |
||
| 450 | |||
| 451 | } |
||
| 452 | |||
| 453 | return $content; |
||
| 454 | |||
| 455 | } |
||
| 456 | |||
| 457 | if (!isset($this->piVars['query']) && empty($this->piVars['extQuery'])) { |
||
| 458 | |||
| 459 | // Extract query and filter from last search. |
||
| 460 | $list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list'); |
||
| 461 | |||
| 462 | if (!empty($list->metadata['searchString'])) { |
||
| 463 | |||
| 464 | if ($list->metadata['options']['source'] == 'search') { |
||
| 465 | |||
| 466 | $search['query'] = $list->metadata['searchString']; |
||
| 467 | |||
| 468 | } |
||
| 469 | |||
| 470 | $search['params'] = $list->metadata['options']['params']; |
||
| 471 | |||
| 472 | } |
||
| 473 | |||
| 474 | // Add javascript for search suggestions if enabled and jQuery autocompletion is available. |
||
| 475 | if (!empty($this->conf['suggest'])) { |
||
| 476 | |||
| 477 | $this->addAutocompleteJS(); |
||
| 478 | |||
| 479 | } |
||
| 480 | |||
| 481 | // Load template file. |
||
| 482 | if (!empty($this->conf['templateFile'])) { |
||
| 483 | |||
| 484 | $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###'); |
||
| 485 | |||
| 486 | } else { |
||
| 487 | |||
| 488 | $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/search/template.tmpl'), '###TEMPLATE###'); |
||
| 489 | |||
| 490 | } |
||
| 491 | |||
| 492 | // Configure @action URL for form. |
||
| 493 | $linkConf = array ( |
||
| 494 | 'parameter' => $GLOBALS['TSFE']->id, |
||
| 495 | 'forceAbsoluteUrl' => 1 |
||
| 496 | ); |
||
| 497 | |||
| 498 | // Fill markers. |
||
| 499 | $markerArray = array ( |
||
| 500 | '###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf), |
||
| 501 | '###LABEL_QUERY###' => (!empty($search['query']) ? $search['query'] : $this->pi_getLL('label.query')), |
||
| 502 | '###LABEL_SUBMIT###' => $this->pi_getLL('label.submit'), |
||
| 503 | '###FIELD_QUERY###' => $this->prefixId.'[query]', |
||
| 504 | '###QUERY###' => (!empty($search['query']) ? $search['query'] : ''), |
||
| 505 | '###FULLTEXTSWITCH###' => $this->addFulltextSwitch($list->metadata['fulltextSearch']), |
||
| 506 | '###FIELD_DOC###' => ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all' ? $this->addCurrentDocument() : ''), |
||
| 507 | '###FIELD_COLL###' => ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all' ? $this->addCurrentCollection() : ''), |
||
| 508 | '###ADDITIONAL_INPUTS###' => $this->addEncryptedCoreName(), |
||
| 509 | '###FACETS_MENU###' => $this->addFacetsMenu(), |
||
| 510 | '###LOGICAL_PAGE###' => $this->addLogicalPage() |
||
| 511 | ); |
||
| 512 | |||
| 513 | // Get additional fields for extended search. |
||
| 514 | $extendedSearch = $this->addExtendedSearch(); |
||
| 515 | |||
| 516 | // Display search form. |
||
| 517 | $content .= $this->cObj->substituteSubpart($this->cObj->substituteMarkerArray($this->template, $markerArray), '###EXT_SEARCH_ENTRY###', $extendedSearch); |
||
| 518 | |||
| 519 | return $this->pi_wrapInBaseClass($content); |
||
| 520 | |||
| 521 | } else { |
||
| 522 | |||
| 523 | // Instantiate search object. |
||
| 524 | $solr = tx_dlf_solr::getInstance($this->conf['solrcore']); |
||
| 525 | |||
| 526 | if (!$solr->ready) { |
||
| 527 | |||
| 528 | if (TYPO3_DLOG) { |
||
| 529 | |||
| 530 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->main('.$content.', [data])] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR, $conf); |
||
| 531 | |||
| 532 | } |
||
| 533 | |||
| 534 | return $content; |
||
| 535 | |||
| 536 | } |
||
| 537 | |||
| 538 | // Build label for result list. |
||
| 539 | $label = $this->pi_getLL('search', '', TRUE); |
||
| 540 | |||
| 541 | if (!empty($this->piVars['query'])) { |
||
| 542 | |||
| 543 | $label .= htmlspecialchars(sprintf($this->pi_getLL('for', ''), $this->piVars['query'])); |
||
| 544 | |||
| 545 | } |
||
| 546 | |||
| 547 | // Prepare query parameters. |
||
| 548 | $params = array (); |
||
| 549 | |||
| 550 | $matches = array (); |
||
| 551 | |||
| 552 | // Set search query. |
||
| 553 | if ((!empty($this->conf['fulltext']) && !empty($this->piVars['fulltext'])) || preg_match('/fulltext:\((.*)\)/', $this->piVars['query'], $matches)) { |
||
| 554 | |||
| 555 | // If the query already is a fulltext query e.g using the facets |
||
| 556 | $this->piVars['query'] = empty($matches[1]) ? $this->piVars['query'] : $matches[1]; |
||
| 557 | |||
| 558 | // Search in fulltext field if applicable. query must not be empty! |
||
| 559 | if (!empty($this->piVars['query'])) { |
||
| 560 | |||
| 561 | $query = 'fulltext:('.tx_dlf_solr::escapeQuery($this->piVars['query']).')'; |
||
| 562 | |||
| 563 | } |
||
| 564 | |||
| 565 | // Add highlighting for fulltext. |
||
| 566 | $params['hl'] = 'true'; |
||
| 567 | |||
| 568 | $params['hl.fl'] = 'fulltext'; |
||
| 569 | |||
| 570 | } else { |
||
| 571 | // Retain given search field if valid. |
||
| 572 | $query = tx_dlf_solr::escapeQueryKeepField($this->piVars['query'], $this->conf['pages']); |
||
| 573 | |||
| 574 | } |
||
| 575 | |||
| 576 | // Add extended search query. |
||
| 577 | if (!empty($this->piVars['extQuery']) && is_array($this->piVars['extQuery'])) { |
||
| 578 | |||
| 579 | $allowedOperators = array ('AND', 'OR', 'NOT'); |
||
| 580 | |||
| 581 | $allowedFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['extendedFields'], TRUE); |
||
| 582 | |||
| 583 | for ($i = 0; $i < count($this->piVars['extQuery']); $i++) { |
||
| 584 | |||
| 585 | if (!empty($this->piVars['extQuery'][$i])) { |
||
| 586 | |||
| 587 | if (in_array($this->piVars['extOperator'][$i], $allowedOperators) && in_array($this->piVars['extField'][$i], $allowedFields)) { |
||
| 588 | |||
| 589 | if (!empty($query)) { |
||
| 590 | |||
| 591 | $query .= ' '.$this->piVars['extOperator'][$i].' '; |
||
| 592 | |||
| 593 | } |
||
| 594 | |||
| 595 | $query .= tx_dlf_indexing::getIndexFieldName($this->piVars['extField'][$i], $this->conf['pages']).':('.tx_dlf_solr::escapeQuery($this->piVars['extQuery'][$i]).')'; |
||
| 596 | |||
| 597 | } |
||
| 598 | |||
| 599 | } |
||
| 600 | |||
| 601 | } |
||
| 602 | |||
| 603 | } |
||
| 604 | |||
| 605 | // Add filter query for faceting. |
||
| 606 | if (!empty($this->piVars['fq'])) { |
||
| 607 | |||
| 608 | $params['fq'] = $this->piVars['fq']; |
||
| 609 | |||
| 610 | } |
||
| 611 | |||
| 612 | // Add filter query for in-document searching. |
||
| 613 | if ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all') { |
||
| 614 | |||
| 615 | if (!empty($this->piVars['id']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['id'])) { |
||
| 616 | |||
| 617 | $params['fq'][] = 'uid:('.$this->piVars['id'].') OR partof:('.$this->piVars['id'].')'; |
||
| 618 | |||
| 619 | $label .= htmlspecialchars(sprintf($this->pi_getLL('in', ''), tx_dlf_document::getTitle($this->piVars['id']))); |
||
| 620 | |||
| 621 | } |
||
| 622 | |||
| 623 | } |
||
| 624 | |||
| 625 | // Add filter query for in-collection searching. |
||
| 626 | if ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all') { |
||
| 627 | |||
| 628 | if (!empty($this->piVars['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['collection'])) { |
||
| 629 | |||
| 630 | $index_name = tx_dlf_helper::getIndexName($this->piVars['collection'], 'tx_dlf_collections', $this->conf['pages']); |
||
| 631 | |||
| 632 | $params['fq'][] = 'collection_faceting:("'.tx_dlf_solr::escapeQuery($index_name).'")'; |
||
| 633 | |||
| 634 | $label .= sprintf($this->pi_getLL('in', '', TRUE), tx_dlf_helper::translate($index_name, 'tx_dlf_collections', $this->conf['pages'])); |
||
| 635 | |||
| 636 | } |
||
| 637 | |||
| 638 | } |
||
| 639 | |||
| 640 | // Add filter query for collection restrictions. |
||
| 641 | if ($this->conf['collections']) { |
||
| 642 | |||
| 643 | $collIds = explode(',', $this->conf['collections']); |
||
| 644 | |||
| 645 | $collIndexNames = array (); |
||
| 646 | |||
| 647 | foreach ($collIds as $collId) { |
||
| 648 | |||
| 649 | $collIndexNames[] = tx_dlf_solr::escapeQuery(tx_dlf_helper::getIndexName(intval($collId), 'tx_dlf_collections', $this->conf['pages'])); |
||
| 650 | |||
| 651 | } |
||
| 652 | |||
| 653 | // Last value is fake and used for distinction in $this->addCurrentCollection() |
||
| 654 | $params['fq'][] = 'collection_faceting:("'.implode('" OR "', $collIndexNames).'" OR "FakeValueForDistinction")'; |
||
| 655 | |||
| 656 | } |
||
| 657 | |||
| 658 | // Set search parameters. |
||
| 659 | $solr->limit = max(intval($this->conf['limit']), 1); |
||
| 660 | |||
| 661 | $solr->cPid = $this->conf['pages']; |
||
| 662 | |||
| 663 | $solr->params = $params; |
||
| 664 | |||
| 665 | // Perform search. |
||
| 666 | $results = $solr->search($query); |
||
| 667 | |||
| 668 | $results->metadata = array ( |
||
| 669 | 'label' => $label, |
||
| 670 | 'description' => '<p class="tx-dlf-search-numHits">'.htmlspecialchars(sprintf($this->pi_getLL('hits', ''), $solr->numberOfHits, count($results))).'</p>', |
||
| 671 | 'thumbnail' => '', |
||
| 672 | 'searchString' => $this->piVars['query'], |
||
| 673 | 'fulltextSearch' => (!empty($this->piVars['fulltext']) ? '1' : '0'), |
||
| 674 | 'options' => $results->metadata['options'] |
||
| 675 | ); |
||
| 676 | |||
| 677 | $results->save(); |
||
| 678 | |||
| 679 | // Clean output buffer. |
||
| 680 | \TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers(); |
||
| 681 | |||
| 682 | $additionalParams = array (); |
||
| 683 | |||
| 684 | if (!empty($this->piVars['logicalPage'])) { |
||
| 685 | |||
| 686 | $additionalParams['logicalPage'] = $this->piVars['logicalPage']; |
||
| 687 | |||
| 688 | } |
||
| 689 | |||
| 690 | // Jump directly to the page view, if there is only one result and it is configured |
||
| 691 | if ($results->count() == 1 && !empty($this->conf['showSingleResult'])) { |
||
| 692 | |||
| 693 | $linkConf['parameter'] = $this->conf['targetPidPageView']; |
||
| 694 | |||
| 695 | $additionalParams['id'] = $results->current()['uid']; |
||
| 696 | $additionalParams['highlight_word'] = preg_replace('/\s\s+/', ';', $results->metadata['searchString']); |
||
| 697 | $additionalParams['page'] = count($results[0]['subparts']) == 1 ? $results[0]['subparts'][0]['page'] : 1; |
||
| 698 | |||
| 699 | } else { |
||
| 700 | |||
| 701 | // Keep some plugin variables. |
||
| 702 | $linkConf['parameter'] = $this->conf['targetPid']; |
||
| 703 | |||
| 704 | if (!empty($this->piVars['order'])) { |
||
| 705 | |||
| 706 | $additionalParams['order'] = $this->piVars['order']; |
||
| 707 | $additionalParams['asc'] = !empty($this->piVars['asc']) ? '1' : '0'; |
||
| 708 | |||
| 709 | } |
||
| 710 | |||
| 711 | } |
||
| 712 | |||
| 713 | $linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, $additionalParams, '', TRUE, FALSE); |
||
| 714 | |||
| 715 | // Send headers. |
||
| 716 | header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL($linkConf))); |
||
| 717 | |||
| 718 | // Flush output buffer and end script processing. |
||
| 719 | ob_end_flush(); |
||
| 720 | |||
| 721 | exit; |
||
| 722 | |||
| 854 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths