| Conditions | 13 |
| Paths | 102 |
| Total Lines | 76 |
| Code Lines | 34 |
| 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 |
||
| 127 | public function resultsFilter($query, $showDeleted = false) |
||
| 128 | { |
||
| 129 | |||
| 130 | $queryFilter = array(); |
||
| 131 | |||
| 132 | // Frontend only |
||
| 133 | $searchResultsFilter = $this->settings['searchResultsFilter']; |
||
| 134 | if(!empty($searchResultsFilter)) { |
||
| 135 | |||
| 136 | // add doctypes |
||
| 137 | if($searchResultsFilter['doctype']) { |
||
| 138 | |||
| 139 | $uids = GeneralUtility::trimExplode(',', $searchResultsFilter['doctype']); |
||
| 140 | $documentTypeRepository = $this->documentTypeRepository; |
||
| 141 | $documentTypes = array(); |
||
| 142 | foreach($uids as $uid) { |
||
| 143 | $documentType = $documentTypeRepository->findByUid($uid); |
||
| 144 | $documentTypes[] = $documentType->getName(); |
||
| 145 | }; |
||
| 146 | $searchResultsFilter['doctype'] = implode(',', $documentTypes); |
||
| 147 | } |
||
| 148 | |||
| 149 | // add date filter |
||
| 150 | $dateFilter = array(); |
||
| 151 | if ($searchResultsFilter['from']) { |
||
| 152 | |||
| 153 | $from = date('d.m.Y', $searchResultsFilter['from']); |
||
| 154 | $dateTime = $this->convertFormDate($from, false); |
||
| 155 | $dateFilter['gte'] = $dateTime->format('Y-m-d'); |
||
| 156 | unset($searchResultsFilter['from']); |
||
| 157 | |||
| 158 | } |
||
| 159 | |||
| 160 | if ($searchResultsFilter['till']) { |
||
| 161 | |||
| 162 | $till = date('d.m.Y', $searchResultsFilter['till']); |
||
| 163 | $dateTime = $this->convertFormDate($till, true); |
||
| 164 | $dateFilter['lte'] = $dateTime->format('Y-m-d'); |
||
| 165 | unset($searchResultsFilter['till']); |
||
| 166 | |||
| 167 | } |
||
| 168 | |||
| 169 | if (isset($dateFilter['gte']) || isset($dateFilter['lte'])) { |
||
| 170 | |||
| 171 | $queryFilter['body']['query']['bool']['must'][] = array('range' => array('distribution_date' => $dateFilter)); |
||
| 172 | |||
| 173 | } |
||
| 174 | |||
| 175 | foreach ($searchResultsFilter as $key => $qry) { |
||
| 176 | |||
| 177 | if(!empty($qry)) { |
||
| 178 | $queryFilter['body']['query']['bool']['must'][] = array('match' => array($key => $qry)); |
||
| 179 | } |
||
| 180 | |||
| 181 | } |
||
| 182 | |||
| 183 | } |
||
| 184 | |||
| 185 | // document must be active |
||
| 186 | if($showDeleted == false) { |
||
| 187 | |||
| 188 | // $queryFilter['body']['query']['bool']['must'][]['term']['STATE'] = 'A'; |
||
| 189 | |||
| 190 | }; |
||
| 191 | |||
| 192 | // add OWNER_ID if present |
||
| 193 | $clients = $this->clientRepository->findAll(); |
||
| 194 | if ($clients) { |
||
| 195 | $client = $clients->getFirst(); |
||
| 196 | if ($client) { |
||
| 197 | // $queryFilter['body']['query']['bool']['must'][]['term']['OWNER_ID'] = $client->getOwnerId(); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | $queryFilter = array_merge_recursive($queryFilter, $query); |
||
| 202 | return $queryFilter; |
||
| 203 | } |
||
| 267 |