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  | 
            ||
| 53 | class Aggregation implements DSL  | 
            ||
| 54 | { | 
            ||
| 55 | /**  | 
            ||
| 56 | * must return type for QueryBuilder usage.  | 
            ||
| 57 | */  | 
            ||
| 58 | public function getType(): string  | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * min aggregation.  | 
            ||
| 65 | *  | 
            ||
| 66 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html  | 
            ||
| 67 | */  | 
            ||
| 68 | public function min(string $name): Min  | 
            ||
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * max aggregation.  | 
            ||
| 75 | *  | 
            ||
| 76 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html  | 
            ||
| 77 | */  | 
            ||
| 78 | public function max(string $name): Max  | 
            ||
| 82 | |||
| 83 | /**  | 
            ||
| 84 | * sum aggregation.  | 
            ||
| 85 | *  | 
            ||
| 86 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html  | 
            ||
| 87 | */  | 
            ||
| 88 | public function sum(string $name): Sum  | 
            ||
| 92 | |||
| 93 | /**  | 
            ||
| 94 | * sum bucket aggregation.  | 
            ||
| 95 | *  | 
            ||
| 96 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html  | 
            ||
| 97 | */  | 
            ||
| 98 | public function sum_bucket(string $name, ?string $bucketsPath = null): SumBucket  | 
            ||
| 102 | |||
| 103 | /**  | 
            ||
| 104 | * avg aggregation.  | 
            ||
| 105 | *  | 
            ||
| 106 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html  | 
            ||
| 107 | */  | 
            ||
| 108 | public function avg(string $name): Avg  | 
            ||
| 112 | |||
| 113 | /**  | 
            ||
| 114 | * avg bucket aggregation.  | 
            ||
| 115 | *  | 
            ||
| 116 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html  | 
            ||
| 117 | */  | 
            ||
| 118 | public function avg_bucket(string $name, ?string $bucketsPath = null): AvgBucket  | 
            ||
| 122 | |||
| 123 | /**  | 
            ||
| 124 | * stats aggregation.  | 
            ||
| 125 | *  | 
            ||
| 126 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html  | 
            ||
| 127 | */  | 
            ||
| 128 | public function stats(string $name): Stats  | 
            ||
| 132 | |||
| 133 | /**  | 
            ||
| 134 | * extended stats aggregation.  | 
            ||
| 135 | *  | 
            ||
| 136 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html  | 
            ||
| 137 | */  | 
            ||
| 138 | public function extended_stats(string $name): ExtendedStats  | 
            ||
| 142 | |||
| 143 | /**  | 
            ||
| 144 | * value count aggregation.  | 
            ||
| 145 | *  | 
            ||
| 146 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html  | 
            ||
| 147 | */  | 
            ||
| 148 | public function value_count(string $name, string $field): ValueCount  | 
            ||
| 152 | |||
| 153 | /**  | 
            ||
| 154 | * percentiles aggregation.  | 
            ||
| 155 | *  | 
            ||
| 156 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html  | 
            ||
| 157 | *  | 
            ||
| 158 | * @param string $name the name of this aggregation  | 
            ||
| 159 | * @param string $field the field on which to perform this aggregation  | 
            ||
| 160 | */  | 
            ||
| 161 | public function percentiles(string $name, ?string $field = null): Percentiles  | 
            ||
| 165 | |||
| 166 | /**  | 
            ||
| 167 | * percentiles_bucket aggregation.  | 
            ||
| 168 | *  | 
            ||
| 169 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html  | 
            ||
| 170 | *  | 
            ||
| 171 | * @param string $name the name of this aggregation  | 
            ||
| 172 | * @param string $bucketsPath the field on which to perform this aggregation  | 
            ||
| 173 | */  | 
            ||
| 174 | public function percentiles_bucket(string $name, ?string $bucketsPath = null): PercentilesBucket  | 
            ||
| 178 | |||
| 179 | /**  | 
            ||
| 180 | * cardinality aggregation.  | 
            ||
| 181 | *  | 
            ||
| 182 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html  | 
            ||
| 183 | */  | 
            ||
| 184 | public function cardinality(string $name): Cardinality  | 
            ||
| 188 | |||
| 189 | /**  | 
            ||
| 190 | * geo bounds aggregation.  | 
            ||
| 191 | *  | 
            ||
| 192 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html  | 
            ||
| 193 | *  | 
            ||
| 194 | * @param string $name  | 
            ||
| 195 | */  | 
            ||
| 196 | public function geo_bounds($name): void  | 
            ||
| 200 | |||
| 201 | /**  | 
            ||
| 202 | * top hits aggregation.  | 
            ||
| 203 | *  | 
            ||
| 204 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html  | 
            ||
| 205 | */  | 
            ||
| 206 | public function top_hits(string $name): TopHits  | 
            ||
| 210 | |||
| 211 | /**  | 
            ||
| 212 | * scripted metric aggregation.  | 
            ||
| 213 | *  | 
            ||
| 214 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html  | 
            ||
| 215 | */  | 
            ||
| 216 | public function scripted_metric(  | 
            ||
| 225 | |||
| 226 | /**  | 
            ||
| 227 | * global aggregation.  | 
            ||
| 228 | *  | 
            ||
| 229 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html  | 
            ||
| 230 | */  | 
            ||
| 231 | public function global(string $name): GlobalAggregation  | 
            ||
| 235 | |||
| 236 | /**  | 
            ||
| 237 | * @deprecated since version 7.1.0, use the "global()" method instead.  | 
            ||
| 238 | */  | 
            ||
| 239 | public function global_agg(string $name): GlobalAggregation  | 
            ||
| 245 | |||
| 246 | /**  | 
            ||
| 247 | * filter aggregation.  | 
            ||
| 248 | *  | 
            ||
| 249 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html  | 
            ||
| 250 | *  | 
            ||
| 251 | * @param AbstractQuery $filter  | 
            ||
| 252 | */  | 
            ||
| 253 | public function filter(string $name, ?AbstractQuery $filter = null): Filter  | 
            ||
| 257 | |||
| 258 | /**  | 
            ||
| 259 | * filters aggregation.  | 
            ||
| 260 | *  | 
            ||
| 261 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html  | 
            ||
| 262 | */  | 
            ||
| 263 | public function filters(string $name): Filters  | 
            ||
| 267 | |||
| 268 | /**  | 
            ||
| 269 | * missing aggregation.  | 
            ||
| 270 | *  | 
            ||
| 271 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html  | 
            ||
| 272 | */  | 
            ||
| 273 | public function missing(string $name, string $field): Missing  | 
            ||
| 277 | |||
| 278 | /**  | 
            ||
| 279 | * nested aggregation.  | 
            ||
| 280 | *  | 
            ||
| 281 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html  | 
            ||
| 282 | *  | 
            ||
| 283 | * @param string $path the nested path for this aggregation  | 
            ||
| 284 | */  | 
            ||
| 285 | public function nested(string $name, string $path): Nested  | 
            ||
| 289 | |||
| 290 | /**  | 
            ||
| 291 | * reverse nested aggregation.  | 
            ||
| 292 | *  | 
            ||
| 293 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html  | 
            ||
| 294 | *  | 
            ||
| 295 | * @param string $name The name of this aggregation  | 
            ||
| 296 | * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.  | 
            ||
| 297 | */  | 
            ||
| 298 | public function reverse_nested(string $name, ?string $path = null): ReverseNested  | 
            ||
| 302 | |||
| 303 | /**  | 
            ||
| 304 | * terms aggregation.  | 
            ||
| 305 | *  | 
            ||
| 306 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html  | 
            ||
| 307 | */  | 
            ||
| 308 | public function terms(string $name): Terms  | 
            ||
| 312 | |||
| 313 | /**  | 
            ||
| 314 | * significant terms aggregation.  | 
            ||
| 315 | *  | 
            ||
| 316 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html  | 
            ||
| 317 | */  | 
            ||
| 318 | public function significant_terms(string $name): SignificantTerms  | 
            ||
| 322 | |||
| 323 | /**  | 
            ||
| 324 | * range aggregation.  | 
            ||
| 325 | *  | 
            ||
| 326 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html  | 
            ||
| 327 | */  | 
            ||
| 328 | public function range(string $name): Range  | 
            ||
| 332 | |||
| 333 | /**  | 
            ||
| 334 | * date range aggregation.  | 
            ||
| 335 | *  | 
            ||
| 336 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html  | 
            ||
| 337 | */  | 
            ||
| 338 | public function date_range(string $name): DateRange  | 
            ||
| 342 | |||
| 343 | /**  | 
            ||
| 344 | * ipv4 range aggregation.  | 
            ||
| 345 | *  | 
            ||
| 346 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html  | 
            ||
| 347 | */  | 
            ||
| 348 | public function ipv4_range(string $name, string $field): IpRange  | 
            ||
| 352 | |||
| 353 | /**  | 
            ||
| 354 | * histogram aggregation.  | 
            ||
| 355 | *  | 
            ||
| 356 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html  | 
            ||
| 357 | *  | 
            ||
| 358 | * @param string $name the name of this aggregation  | 
            ||
| 359 | * @param string $field the name of the field on which to perform the aggregation  | 
            ||
| 360 | * @param int $interval the interval by which documents will be bucketed  | 
            ||
| 361 | */  | 
            ||
| 362 | public function histogram(string $name, string $field, $interval): Histogram  | 
            ||
| 366 | |||
| 367 | /**  | 
            ||
| 368 | * date histogram aggregation.  | 
            ||
| 369 | *  | 
            ||
| 370 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html  | 
            ||
| 371 | *  | 
            ||
| 372 | * @param string $name the name of this aggregation  | 
            ||
| 373 | * @param string $field the name of the field on which to perform the aggregation  | 
            ||
| 374 | * @param int|string $interval the interval by which documents will be bucketed  | 
            ||
| 375 | */  | 
            ||
| 376 | public function date_histogram(string $name, string $field, $interval): DateHistogram  | 
            ||
| 380 | |||
| 381 | /**  | 
            ||
| 382 | * geo distance aggregation.  | 
            ||
| 383 | *  | 
            ||
| 384 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html  | 
            ||
| 385 | *  | 
            ||
| 386 | * @param string $name the name if this aggregation  | 
            ||
| 387 | * @param string $field the field on which to perform this aggregation  | 
            ||
| 388 | * @param array|string $origin the point from which distances will be calculated  | 
            ||
| 389 | */  | 
            ||
| 390 | public function geo_distance(string $name, string $field, $origin): GeoDistance  | 
            ||
| 394 | |||
| 395 | /**  | 
            ||
| 396 | * geohash grid aggregation.  | 
            ||
| 397 | *  | 
            ||
| 398 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html  | 
            ||
| 399 | *  | 
            ||
| 400 | * @param string $name the name of this aggregation  | 
            ||
| 401 | * @param string $field the field on which to perform this aggregation  | 
            ||
| 402 | */  | 
            ||
| 403 | public function geohash_grid(string $name, string $field): GeohashGrid  | 
            ||
| 407 | |||
| 408 | /**  | 
            ||
| 409 | * geotile grid aggregation.  | 
            ||
| 410 | *  | 
            ||
| 411 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geotilegrid-aggregation.html  | 
            ||
| 412 | *  | 
            ||
| 413 | * @param string $name the name of this aggregation  | 
            ||
| 414 | * @param string $field the field on which to perform this aggregation  | 
            ||
| 415 | */  | 
            ||
| 416 | public function geotile_grid(string $name, string $field): GeotileGridAggregation  | 
            ||
| 420 | |||
| 421 | /**  | 
            ||
| 422 | * bucket script aggregation.  | 
            ||
| 423 | *  | 
            ||
| 424 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html  | 
            ||
| 425 | */  | 
            ||
| 426 | public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript  | 
            ||
| 430 | |||
| 431 | /**  | 
            ||
| 432 | * serial diff aggregation.  | 
            ||
| 433 | *  | 
            ||
| 434 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html  | 
            ||
| 435 | */  | 
            ||
| 436 | public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff  | 
            ||
| 440 | |||
| 441 | /**  | 
            ||
| 442 | * adjacency matrix aggregation.  | 
            ||
| 443 | *  | 
            ||
| 444 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html  | 
            ||
| 445 | */  | 
            ||
| 446 | public function adjacency_matrix(string $name): AdjacencyMatrix  | 
            ||
| 450 | |||
| 451 | /**  | 
            ||
| 452 | * sampler aggregation.  | 
            ||
| 453 | *  | 
            ||
| 454 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html  | 
            ||
| 455 | */  | 
            ||
| 456 | public function sampler(string $name): Sampler  | 
            ||
| 460 | |||
| 461 | /**  | 
            ||
| 462 | * diversified sampler aggregation.  | 
            ||
| 463 | *  | 
            ||
| 464 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html  | 
            ||
| 465 | */  | 
            ||
| 466 | public function diversified_sampler(string $name): DiversifiedSampler  | 
            ||
| 470 | |||
| 471 | /**  | 
            ||
| 472 | * weighted avg aggregation.  | 
            ||
| 473 | *  | 
            ||
| 474 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html  | 
            ||
| 475 | */  | 
            ||
| 476 | public function weighted_avg(string $name): WeightedAvg  | 
            ||
| 480 | |||
| 481 | /**  | 
            ||
| 482 | * composite aggregation.  | 
            ||
| 483 | *  | 
            ||
| 484 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html  | 
            ||
| 485 | */  | 
            ||
| 486 | public function composite(string $name): Composite  | 
            ||
| 490 | }  | 
            ||
| 491 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.