| Total Complexity | 42 |
| Total Lines | 252 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AbstractSearchController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractSearchController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | abstract class AbstractSearchController extends \EWW\Dpf\Controller\AbstractController |
||
| 21 | { |
||
| 22 | // search terms |
||
| 23 | private static $terms = ['_id', 'OWNER_ID', 'submitter', 'project']; |
||
| 24 | |||
| 25 | // search matches |
||
| 26 | private static $matches = ['title', 'abstract', 'author', 'language', 'tag', 'corporation', 'doctype', 'collections']; |
||
| 27 | |||
| 28 | |||
| 29 | protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) |
||
| 30 | { |
||
| 31 | parent::initializeView($view); |
||
| 32 | |||
| 33 | if (TYPO3_MODE === 'BE') { |
||
| 34 | $selectedPageId = (int) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'); |
||
| 35 | if ($selectedPageId) { |
||
| 36 | $client = $this->clientRepository->findAll()->current(); |
||
| 37 | } |
||
| 38 | if (!$client) { |
||
| 39 | $this->redirect('list','Document'); |
||
| 40 | } else { |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * get results from elastic search |
||
| 47 | * @param array $query elasticsearch search query |
||
| 48 | * @return array results |
||
| 49 | */ |
||
| 50 | public function getResultList($query, $type) |
||
| 51 | { |
||
| 52 | |||
| 53 | $elasticSearch = $this->objectManager->get(ElasticSearch::class); |
||
| 54 | $results = $elasticSearch->search($query, $type); |
||
| 55 | |||
| 56 | return $results; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * prepare fulltext query |
||
| 61 | * @param string $searchString |
||
| 62 | * @return array query |
||
| 63 | */ |
||
| 64 | public function searchFulltext($searchString) |
||
| 81 | |||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * build array for elasticsearch |
||
| 86 | * @return array Elasticsearch query array |
||
| 87 | */ |
||
| 88 | public function extendedSearch($searchArray = array()) |
||
| 89 | { |
||
| 90 | |||
| 91 | $query = array(); |
||
| 92 | $filter = array(); |
||
| 93 | foreach ($searchArray as $key => $qry) { |
||
| 94 | $qry = trim($qry); |
||
| 95 | |||
| 96 | if (!empty($qry) && in_array($key, self::$matches)) { |
||
| 97 | |||
| 98 | $query['body']['query']['bool']['must'][] = array('match' => array($key => $qry)); |
||
| 99 | |||
| 100 | } elseif (!empty($qry) && in_array($key, self::$terms)) { |
||
| 101 | |||
| 102 | $query['body']['query']['bool']['must'][] = array('term' => array($key => $qry)); |
||
| 103 | |||
| 104 | } elseif (!empty($qry) && $key == 'from') { |
||
| 105 | |||
| 106 | if ($dateTime = $this->convertFormDate($qry, false)) { |
||
| 107 | $filter['gte'] = $dateTime->format('Y-m-d'); |
||
| 108 | } |
||
| 109 | |||
| 110 | } elseif (!empty($qry) && $key == 'till') { |
||
| 111 | |||
| 112 | if ($dateTime = $this->convertFormDate($qry, true)) { |
||
| 113 | $filter['lte'] = $dateTime->format('Y-m-d'); |
||
| 114 | } |
||
| 115 | |||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | if (isset($filter['gte']) || isset($filter['lte'])) { |
||
| 120 | |||
| 121 | $query['body']['query']['bool']['must'][] = array('range' => array('distribution_date' => $filter)); |
||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | $showDeleted = ($searchArray['showDeleted'] == 'true') ? true : false; |
||
| 126 | $query = $this->resultsFilter($query, $showDeleted); |
||
| 127 | return $query; |
||
| 128 | |||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * build array for elasticsearch resultfilter |
||
| 133 | * @param array Elasticsearch query array |
||
| 134 | * @return array Elasticsearch queryFilter array |
||
| 135 | */ |
||
| 136 | public function resultsFilter($query, $showDeleted = false) |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Convert date from form input into DateTime object. |
||
| 216 | * |
||
| 217 | * A 4 character string is taken for a year and the returning |
||
| 218 | * DateTime object is supplemented with either the 01. Jan or 31. Dec |
||
| 219 | * depending on the $intervalEnd parameter. This allows querying time |
||
| 220 | * intervals like `2000 to 2003`. |
||
| 221 | * |
||
| 222 | * @param string $dateString Date literal from form |
||
| 223 | * @param bool $intervalEnd Fills missing values with the maximum possible date if true |
||
| 224 | * @return DateTime Determined date |
||
| 225 | */ |
||
| 226 | public function convertFormDate($dateString, $intervalEnd = false) |
||
| 227 | { |
||
| 228 | try { |
||
| 229 | if (strlen($dateString) == 4) { |
||
| 230 | // assuming year |
||
| 231 | $year = $dateString; |
||
| 232 | $month = $intervalEnd ? "12" : "01"; |
||
| 233 | $day = $intervalEnd ? "31" : "01"; |
||
| 234 | return new \DateTime("$year-$month-$day"); |
||
| 235 | } else { |
||
| 236 | return new \DateTime($dateString); |
||
| 237 | } |
||
| 238 | } catch (\Exception $_) { |
||
| 239 | return false; |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * escapes lucene reserved characters from string |
||
| 245 | * @param $string |
||
| 246 | * @return mixed |
||
| 247 | */ |
||
| 248 | private function escapeQuery($string) |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * converts a date from dd.mm.yy to yyyy-dd-mm |
||
| 264 | * @param $date |
||
| 265 | * @return string |
||
| 266 | */ |
||
| 267 | public function formatDate($date) |
||
| 272 | } |
||
| 273 | } |
||
| 274 |
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