Complex classes like Aggregation often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Aggregation, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
54 | class Aggregation implements DSL |
||
55 | { |
||
56 | /** |
||
57 | * must return type for QueryBuilder usage. |
||
58 | */ |
||
59 | public function getType(): string |
||
63 | |||
64 | /** |
||
65 | * min aggregation. |
||
66 | * |
||
67 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html |
||
68 | */ |
||
69 | public function min(string $name): Min |
||
73 | |||
74 | /** |
||
75 | * max aggregation. |
||
76 | * |
||
77 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html |
||
78 | */ |
||
79 | public function max(string $name): Max |
||
83 | |||
84 | /** |
||
85 | * sum aggregation. |
||
86 | * |
||
87 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html |
||
88 | */ |
||
89 | public function sum(string $name): Sum |
||
93 | |||
94 | /** |
||
95 | * sum bucket aggregation. |
||
96 | * |
||
97 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html |
||
98 | */ |
||
99 | public function sum_bucket(string $name, ?string $bucketsPath = null): SumBucket |
||
103 | |||
104 | /** |
||
105 | * avg aggregation. |
||
106 | * |
||
107 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html |
||
108 | */ |
||
109 | public function avg(string $name): Avg |
||
113 | |||
114 | /** |
||
115 | * avg bucket aggregation. |
||
116 | * |
||
117 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html |
||
118 | */ |
||
119 | public function avg_bucket(string $name, ?string $bucketsPath = null): AvgBucket |
||
123 | |||
124 | /** |
||
125 | * stats aggregation. |
||
126 | * |
||
127 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html |
||
128 | */ |
||
129 | public function stats(string $name): Stats |
||
133 | |||
134 | /** |
||
135 | * extended stats aggregation. |
||
136 | * |
||
137 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html |
||
138 | */ |
||
139 | public function extended_stats(string $name): ExtendedStats |
||
143 | |||
144 | /** |
||
145 | * value count aggregation. |
||
146 | * |
||
147 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html |
||
148 | */ |
||
149 | public function value_count(string $name, string $field): ValueCount |
||
153 | |||
154 | /** |
||
155 | * percentiles aggregation. |
||
156 | * |
||
157 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html |
||
158 | * |
||
159 | * @param string $name the name of this aggregation |
||
160 | * @param string $field the field on which to perform this aggregation |
||
161 | */ |
||
162 | public function percentiles(string $name, ?string $field = null): Percentiles |
||
166 | |||
167 | /** |
||
168 | * percentiles_bucket aggregation. |
||
169 | * |
||
170 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html |
||
171 | * |
||
172 | * @param string $name the name of this aggregation |
||
173 | * @param string $bucketsPath the field on which to perform this aggregation |
||
174 | */ |
||
175 | public function percentiles_bucket(string $name, ?string $bucketsPath = null): PercentilesBucket |
||
179 | |||
180 | /** |
||
181 | * cardinality aggregation. |
||
182 | * |
||
183 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html |
||
184 | */ |
||
185 | public function cardinality(string $name): Cardinality |
||
189 | |||
190 | /** |
||
191 | * geo bounds aggregation. |
||
192 | * |
||
193 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html |
||
194 | * |
||
195 | * @param string $name |
||
196 | */ |
||
197 | public function geo_bounds($name): void |
||
201 | |||
202 | /** |
||
203 | * top hits aggregation. |
||
204 | * |
||
205 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html |
||
206 | */ |
||
207 | public function top_hits(string $name): TopHits |
||
211 | |||
212 | /** |
||
213 | * scripted metric aggregation. |
||
214 | * |
||
215 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html |
||
216 | */ |
||
217 | public function scripted_metric( |
||
226 | |||
227 | /** |
||
228 | * global aggregation. |
||
229 | * |
||
230 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html |
||
231 | */ |
||
232 | public function global(string $name): GlobalAggregation |
||
236 | |||
237 | /** |
||
238 | * @deprecated since version 7.1.0, use the "global()" method instead. |
||
239 | */ |
||
240 | public function global_agg(string $name): GlobalAggregation |
||
246 | |||
247 | /** |
||
248 | * filter aggregation. |
||
249 | * |
||
250 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html |
||
251 | * |
||
252 | * @param AbstractQuery $filter |
||
253 | */ |
||
254 | public function filter(string $name, ?AbstractQuery $filter = null): Filter |
||
258 | |||
259 | /** |
||
260 | * filters aggregation. |
||
261 | * |
||
262 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html |
||
263 | */ |
||
264 | public function filters(string $name): Filters |
||
268 | |||
269 | /** |
||
270 | * missing aggregation. |
||
271 | * |
||
272 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html |
||
273 | */ |
||
274 | public function missing(string $name, string $field): Missing |
||
278 | |||
279 | /** |
||
280 | * nested aggregation. |
||
281 | * |
||
282 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html |
||
283 | * |
||
284 | * @param string $path the nested path for this aggregation |
||
285 | */ |
||
286 | public function nested(string $name, string $path): Nested |
||
290 | |||
291 | /** |
||
292 | * reverse nested aggregation. |
||
293 | * |
||
294 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html |
||
295 | * |
||
296 | * @param string $name The name of this aggregation |
||
297 | * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document. |
||
298 | */ |
||
299 | public function reverse_nested(string $name, ?string $path = null): ReverseNested |
||
303 | |||
304 | /** |
||
305 | * terms aggregation. |
||
306 | * |
||
307 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html |
||
308 | */ |
||
309 | public function terms(string $name): Terms |
||
313 | |||
314 | /** |
||
315 | * significant terms aggregation. |
||
316 | * |
||
317 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html |
||
318 | */ |
||
319 | public function significant_terms(string $name): SignificantTerms |
||
323 | |||
324 | /** |
||
325 | * range aggregation. |
||
326 | * |
||
327 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html |
||
328 | */ |
||
329 | public function range(string $name): Range |
||
333 | |||
334 | /** |
||
335 | * date range aggregation. |
||
336 | * |
||
337 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html |
||
338 | */ |
||
339 | public function date_range(string $name): DateRange |
||
343 | |||
344 | /** |
||
345 | * ipv4 range aggregation. |
||
346 | * |
||
347 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html |
||
348 | */ |
||
349 | public function ipv4_range(string $name, string $field): IpRange |
||
353 | |||
354 | /** |
||
355 | * histogram aggregation. |
||
356 | * |
||
357 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html |
||
358 | * |
||
359 | * @param string $name the name of this aggregation |
||
360 | * @param string $field the name of the field on which to perform the aggregation |
||
361 | * @param int $interval the interval by which documents will be bucketed |
||
362 | */ |
||
363 | public function histogram(string $name, string $field, $interval): Histogram |
||
367 | |||
368 | /** |
||
369 | * date histogram aggregation. |
||
370 | * |
||
371 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html |
||
372 | * |
||
373 | * @param string $name the name of this aggregation |
||
374 | * @param string $field the name of the field on which to perform the aggregation |
||
375 | * @param int|string $interval the interval by which documents will be bucketed |
||
376 | */ |
||
377 | public function date_histogram(string $name, string $field, $interval): DateHistogram |
||
381 | |||
382 | /** |
||
383 | * geo distance aggregation. |
||
384 | * |
||
385 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html |
||
386 | * |
||
387 | * @param string $name the name if this aggregation |
||
388 | * @param string $field the field on which to perform this aggregation |
||
389 | * @param array|string $origin the point from which distances will be calculated |
||
390 | */ |
||
391 | public function geo_distance(string $name, string $field, $origin): GeoDistance |
||
395 | |||
396 | /** |
||
397 | * geohash grid aggregation. |
||
398 | * |
||
399 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html |
||
400 | * |
||
401 | * @param string $name the name of this aggregation |
||
402 | * @param string $field the field on which to perform this aggregation |
||
403 | */ |
||
404 | public function geohash_grid(string $name, string $field): GeohashGrid |
||
408 | |||
409 | /** |
||
410 | * geotile grid aggregation. |
||
411 | * |
||
412 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geotilegrid-aggregation.html |
||
413 | * |
||
414 | * @param string $name the name of this aggregation |
||
415 | * @param string $field the field on which to perform this aggregation |
||
416 | */ |
||
417 | public function geotile_grid(string $name, string $field): GeotileGridAggregation |
||
421 | |||
422 | /** |
||
423 | * bucket script aggregation. |
||
424 | * |
||
425 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html |
||
426 | */ |
||
427 | public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript |
||
431 | |||
432 | /** |
||
433 | * serial diff aggregation. |
||
434 | * |
||
435 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html |
||
436 | */ |
||
437 | public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff |
||
441 | |||
442 | /** |
||
443 | * adjacency matrix aggregation. |
||
444 | * |
||
445 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html |
||
446 | */ |
||
447 | public function adjacency_matrix(string $name): AdjacencyMatrix |
||
451 | |||
452 | /** |
||
453 | * sampler aggregation. |
||
454 | * |
||
455 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html |
||
456 | */ |
||
457 | public function sampler(string $name): Sampler |
||
461 | |||
462 | /** |
||
463 | * diversified sampler aggregation. |
||
464 | * |
||
465 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html |
||
466 | */ |
||
467 | public function diversified_sampler(string $name): DiversifiedSampler |
||
471 | |||
472 | /** |
||
473 | * weighted avg aggregation. |
||
474 | * |
||
475 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html |
||
476 | */ |
||
477 | public function weighted_avg(string $name): WeightedAvg |
||
481 | |||
482 | /** |
||
483 | * composite aggregation. |
||
484 | * |
||
485 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html |
||
486 | */ |
||
487 | public function composite(string $name): Composite |
||
491 | |||
492 | /** |
||
493 | * normalize aggregation. |
||
494 | * |
||
495 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-normalize-aggregation.html |
||
496 | */ |
||
497 | public function normalize(string $name, ?string $bucketsPath = null, ?string $method = null): NormalizeAggregation |
||
501 | } |
||
502 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.