| Conditions | 14 |
| Paths | 192 |
| Total Lines | 53 |
| Code Lines | 25 |
| Lines | 6 |
| Ratio | 11.32 % |
| Changes | 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 |
||
| 30 | public function parse(array $data, ParsingDispatcher $parsingDispatcher) |
||
| 31 | { |
||
| 32 | $query = $this->buildQuery(); |
||
| 33 | |||
| 34 | // Criteria |
||
| 35 | // -- FullTextCriterion |
||
| 36 | if (array_key_exists('Criteria', $data) && is_array($data['Criteria'])) { |
||
| 37 | $message = 'The Criteria element is deprecated since ezpublish-kernel 6.6.0, and will be removed in 7.0. Use Filter instead.'; |
||
| 38 | if (array_key_exists('Filter', $data) && is_array($data['Filter'])) { |
||
| 39 | $message .= ' The Criteria element will be merged into Filter.'; |
||
| 40 | $data['Filter'] = array_merge($data['Filter'], $data['Criteria']); |
||
| 41 | } else { |
||
| 42 | $data['Filter'] = $data['Criteria']; |
||
| 43 | } |
||
| 44 | |||
| 45 | @trigger_error($message, E_USER_DEPRECATED); |
||
|
|
|||
| 46 | } |
||
| 47 | |||
| 48 | View Code Duplication | if (array_key_exists('Filter', $data) && is_array($data['Filter'])) { |
|
| 49 | $query->filter = $this->processCriteriaArray($data['Filter'], $parsingDispatcher); |
||
| 50 | } |
||
| 51 | |||
| 52 | View Code Duplication | if (array_key_exists('Query', $data) && is_array($data['Query'])) { |
|
| 53 | $query->query = $this->processCriteriaArray($data['Query'], $parsingDispatcher); |
||
| 54 | } |
||
| 55 | |||
| 56 | // limit |
||
| 57 | if (array_key_exists('limit', $data)) { |
||
| 58 | $query->limit = (int)$data['limit']; |
||
| 59 | } |
||
| 60 | |||
| 61 | // offset |
||
| 62 | if (array_key_exists('offset', $data)) { |
||
| 63 | $query->offset = (int)$data['offset']; |
||
| 64 | } |
||
| 65 | |||
| 66 | // SortClauses |
||
| 67 | // -- [SortClauseName: direction|data] |
||
| 68 | if (array_key_exists('SortClauses', $data)) { |
||
| 69 | $sortClauses = []; |
||
| 70 | foreach ($data['SortClauses'] as $sortClauseName => $sortClauseData) { |
||
| 71 | $sortClauses[] = $this->dispatchSortClause($sortClauseName, $sortClauseData, $parsingDispatcher); |
||
| 72 | } |
||
| 73 | $query->sortClauses = $sortClauses; |
||
| 74 | } |
||
| 75 | |||
| 76 | // FacetBuilders |
||
| 77 | // -- contentTypeFacetBuilder |
||
| 78 | if (array_key_exists('FacetBuilders', $data)) { |
||
| 79 | } |
||
| 80 | |||
| 81 | return $query; |
||
| 82 | } |
||
| 83 | |||
| 106 |
If you suppress an error, we recommend checking for the error condition explicitly: