| Conditions | 10 |
| Paths | 20 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 37 | public function createFacetResult(FacetBuilder $facetBuilder, $fields = [], $queries = [], $dates = [], $ranges = []) |
||
| 38 | { |
||
| 39 | $facetKey = $this->getFacetKey($facetBuilder); |
||
| 40 | $fieldNames = []; |
||
| 41 | foreach ((array) $facetBuilder->fieldPaths as $fieldPath) { |
||
| 42 | $fieldNames[] = \eZSolr::getFieldName($fieldPath, false, 'facet'); |
||
| 43 | } |
||
| 44 | |||
| 45 | $entries = []; |
||
| 46 | $total = 0; |
||
| 47 | |||
| 48 | foreach ($fields as $field) { |
||
| 49 | if ( |
||
| 50 | (isset($field['facet_key']) && $field['facet_key'] == $facetKey) || |
||
| 51 | (!isset($field['facet_key']) && in_array($field['field'], $fieldNames)) |
||
| 52 | ) { |
||
| 53 | foreach ($field['countList'] as $word => $count) { |
||
| 54 | $entries[$word] = $count; |
||
| 55 | } |
||
| 56 | |||
| 57 | foreach ($entries as $word => $count) { |
||
| 58 | $total += intval($count); |
||
| 59 | } |
||
| 60 | |||
| 61 | if (isset($field['facet_key'])) { |
||
| 62 | break; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | return new FieldFacet([ |
||
| 68 | 'name' => $facetBuilder->name, |
||
| 69 | 'entries' => $entries, |
||
| 70 | 'totalCount' => $total, |
||
| 71 | ]); |
||
| 72 | } |
||
| 73 | } |