| Conditions | 13 |
| Paths | 10 |
| Total Lines | 65 |
| Code Lines | 35 |
| 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 |
||
| 95 | public function build(): array |
||
| 96 | { |
||
| 97 | $output = []; |
||
| 98 | |||
| 99 | if (1 === sizeof($this->queries) && 0 === sizeof($this->filters) && 0 === sizeof($this->aggregations)) { |
||
| 100 | $query = current($this->queries); |
||
| 101 | |||
| 102 | return $this->addAggregation([ |
||
| 103 | 'query' => [ |
||
| 104 | $query['queryType'] => [ |
||
| 105 | $query['fieldName'] => $query['fieldValue'], |
||
| 106 | ], |
||
| 107 | ], |
||
| 108 | ]); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (1 === sizeof($this->filters)) { |
||
| 112 | $filters = current($this->filters); |
||
| 113 | $output['bool'] = [ |
||
| 114 | 'filter' => [ |
||
| 115 | $filters['filterType'] => [ |
||
| 116 | $filters['fieldName'] => $filters['fieldValue'], |
||
| 117 | ], |
||
| 118 | ], |
||
| 119 | ]; |
||
| 120 | |||
| 121 | return $this->addAggregation(['query' => $output]); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (sizeof($this->filters) > 1 && sizeof($this->queries) > 1) { |
||
| 125 | $output['bool'] = [ |
||
| 126 | ]; |
||
| 127 | } |
||
| 128 | |||
| 129 | if (sizeof($this->queries) > 1) { |
||
| 130 | $output['bool']['must'] = []; |
||
| 131 | foreach ($this->queries as $query) { |
||
| 132 | $qualifierType = $query['qualifierType']; |
||
| 133 | if (!isset($output['bool'][$qualifierType])) { |
||
| 134 | $output['bool'][$qualifierType] = []; |
||
| 135 | } |
||
| 136 | $output['bool'][$qualifierType][] = [ |
||
| 137 | $query['queryType'] => [ |
||
| 138 | $query['fieldName'] => $query['fieldValue'], |
||
| 139 | ], |
||
| 140 | ]; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | if (sizeof($this->filters) > 1) { |
||
| 145 | $output['bool']['filter']['bool'] = []; |
||
| 146 | foreach ($this->filters as $filter) { |
||
| 147 | $qualifierType = $filter['qualifierType']; |
||
| 148 | if (!isset($output['bool']['filter']['bool'][$qualifierType])) { |
||
| 149 | $output['bool']['filter']['bool'][$qualifierType] = []; |
||
| 150 | } |
||
| 151 | $output['bool']['filter']['bool'][$qualifierType][] = [ |
||
| 152 | $filter['filterType'] => [ |
||
| 153 | $filter['fieldName'] => $filter['fieldValue'], |
||
| 154 | ], |
||
| 155 | ]; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | return $this->addAggregation(['query' => $output]); |
||
| 160 | } |
||
| 198 |