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