| Total Complexity | 42 |
| Total Lines | 251 |
| 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 | } |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * get results from elastic search |
||
| 46 | * @param array $query elasticsearch search query |
||
| 47 | * @return array results |
||
| 48 | */ |
||
| 49 | public function getResultList($query, $type) |
||
| 50 | { |
||
| 51 | |||
| 52 | $elasticSearch = $this->objectManager->get(ElasticSearch::class); |
||
| 53 | $results = $elasticSearch->search($query, $type); |
||
| 54 | |||
| 55 | return $results; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * prepare fulltext query |
||
| 60 | * @param string $searchString |
||
| 61 | * @return array query |
||
| 62 | */ |
||
| 63 | public function searchFulltext($searchString) |
||
| 80 | |||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * build array for elasticsearch |
||
| 85 | * @return array Elasticsearch query array |
||
| 86 | */ |
||
| 87 | public function extendedSearch($searchArray = array()) |
||
| 88 | { |
||
| 89 | |||
| 90 | $query = array(); |
||
| 91 | $filter = array(); |
||
| 92 | foreach ($searchArray as $key => $qry) { |
||
| 93 | $qry = trim($qry); |
||
| 94 | |||
| 95 | if (!empty($qry) && in_array($key, self::$matches)) { |
||
| 96 | |||
| 97 | $query['body']['query']['bool']['must'][] = array('match' => array($key => $qry)); |
||
| 98 | |||
| 99 | } elseif (!empty($qry) && in_array($key, self::$terms)) { |
||
| 100 | |||
| 101 | $query['body']['query']['bool']['must'][] = array('term' => array($key => $qry)); |
||
| 102 | |||
| 103 | } elseif (!empty($qry) && $key == 'from') { |
||
| 104 | |||
| 105 | if ($dateTime = $this->convertFormDate($qry, false)) { |
||
| 106 | $filter['gte'] = $dateTime->format('Y-m-d'); |
||
| 107 | } |
||
| 108 | |||
| 109 | } elseif (!empty($qry) && $key == 'till') { |
||
| 110 | |||
| 111 | if ($dateTime = $this->convertFormDate($qry, true)) { |
||
| 112 | $filter['lte'] = $dateTime->format('Y-m-d'); |
||
| 113 | } |
||
| 114 | |||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | if (isset($filter['gte']) || isset($filter['lte'])) { |
||
| 119 | |||
| 120 | $query['body']['query']['bool']['must'][] = array('range' => array('distribution_date' => $filter)); |
||
| 121 | |||
| 122 | } |
||
| 123 | |||
| 124 | $showDeleted = ($searchArray['showDeleted'] == 'true') ? true : false; |
||
| 125 | $query = $this->resultsFilter($query, $showDeleted); |
||
| 126 | return $query; |
||
| 127 | |||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * build array for elasticsearch resultfilter |
||
| 132 | * @param array Elasticsearch query array |
||
| 133 | * @return array Elasticsearch queryFilter array |
||
| 134 | */ |
||
| 135 | public function resultsFilter($query, $showDeleted = false) |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Convert date from form input into DateTime object. |
||
| 215 | * |
||
| 216 | * A 4 character string is taken for a year and the returning |
||
| 217 | * DateTime object is supplemented with either the 01. Jan or 31. Dec |
||
| 218 | * depending on the $intervalEnd parameter. This allows querying time |
||
| 219 | * intervals like `2000 to 2003`. |
||
| 220 | * |
||
| 221 | * @param string $dateString Date literal from form |
||
| 222 | * @param bool $intervalEnd Fills missing values with the maximum possible date if true |
||
| 223 | * @return DateTime Determined date |
||
| 224 | */ |
||
| 225 | public function convertFormDate($dateString, $intervalEnd = false) |
||
| 226 | { |
||
| 227 | try { |
||
| 228 | if (strlen($dateString) == 4) { |
||
| 229 | // assuming year |
||
| 230 | $year = $dateString; |
||
| 231 | $month = $intervalEnd ? "12" : "01"; |
||
| 232 | $day = $intervalEnd ? "31" : "01"; |
||
| 233 | return new \DateTime("$year-$month-$day"); |
||
| 234 | } else { |
||
| 235 | return new \DateTime($dateString); |
||
| 236 | } |
||
| 237 | } catch (\Exception $_) { |
||
| 238 | return false; |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * escapes lucene reserved characters from string |
||
| 244 | * @param $string |
||
| 245 | * @return mixed |
||
| 246 | */ |
||
| 247 | private function escapeQuery($string) |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * converts a date from dd.mm.yy to yyyy-dd-mm |
||
| 263 | * @param $date |
||
| 264 | * @return string |
||
| 265 | */ |
||
| 266 | public function formatDate($date) |
||
| 271 | } |
||
| 272 | } |
||
| 273 |
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