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