Complex classes like AbstractUpdateAction 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 AbstractUpdateAction, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class AbstractUpdateAction extends Param |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var Document |
||
| 15 | */ |
||
| 16 | protected $_upsert; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Sets the id of the document. |
||
| 20 | */ |
||
| 21 | public function setId(?string $id = null): self |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Returns document id. |
||
| 28 | * |
||
| 29 | * @return string|null Document id |
||
| 30 | */ |
||
| 31 | public function getId(): ?string |
||
| 35 | |||
| 36 | public function hasId(): bool |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Sets the document index name. |
||
| 43 | * |
||
| 44 | * @param Index|string $index Index name |
||
| 45 | */ |
||
| 46 | public function setIndex($index): self |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Get the document index name. |
||
| 57 | * |
||
| 58 | * @throws \Elastica\Exception\InvalidException |
||
| 59 | * |
||
| 60 | * @return string Index name |
||
| 61 | */ |
||
| 62 | public function getIndex() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Sets the sequence number of a document for use with optimistic concurrency control. |
||
| 69 | * |
||
| 70 | * @param int $number Sequence Number |
||
| 71 | * |
||
| 72 | * @return $this |
||
| 73 | * |
||
| 74 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html |
||
| 75 | */ |
||
| 76 | public function setSequenceNumber($number) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Returns document version. |
||
| 83 | * |
||
| 84 | * @return int|string Document version |
||
| 85 | */ |
||
| 86 | public function getSequenceNumber() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return bool |
||
| 93 | */ |
||
| 94 | public function hasSequenceNumber() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Sets the prmary term of a document for use with optimistic concurrency control. |
||
| 101 | * |
||
| 102 | * @param int $term Primary Term |
||
| 103 | * |
||
| 104 | * @return $this |
||
| 105 | * |
||
| 106 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html |
||
| 107 | */ |
||
| 108 | public function setPrimaryTerm($term) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Returns document version. |
||
| 115 | * |
||
| 116 | * @return int|string Document version |
||
| 117 | */ |
||
| 118 | public function getPrimaryTerm() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @return bool |
||
| 125 | */ |
||
| 126 | public function hasPrimaryTerm() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @deprecated |
||
| 133 | * Sets the version of a document for use with optimistic concurrency control. |
||
| 134 | * |
||
| 135 | * @param int $version Document version |
||
| 136 | * |
||
| 137 | * @return $this |
||
| 138 | * |
||
| 139 | * @see https://www.elastic.co/blog/versioning |
||
| 140 | */ |
||
| 141 | public function setVersion($version) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @deprecated |
||
| 150 | * Returns document version. |
||
| 151 | * |
||
| 152 | * @return int|string Document version |
||
| 153 | */ |
||
| 154 | public function getVersion() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @deprecated |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | public function hasVersion() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @deprecated |
||
| 170 | * Sets the version_type of a document |
||
| 171 | * Default in ES is internal, but you can set to external to use custom versioning. |
||
| 172 | * |
||
| 173 | * @param string $versionType Document version type |
||
| 174 | * |
||
| 175 | * @return $this |
||
| 176 | */ |
||
| 177 | public function setVersionType($versionType) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @deprecated |
||
| 186 | * Returns document version type. |
||
| 187 | * |
||
| 188 | * @return int|string Document version type |
||
| 189 | */ |
||
| 190 | public function getVersionType() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @deprecated |
||
| 197 | * @return bool |
||
| 198 | */ |
||
| 199 | public function hasVersionType() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Set operation type. |
||
| 206 | * |
||
| 207 | * @param string $opType Only accept create |
||
| 208 | * |
||
| 209 | * @return $this |
||
| 210 | */ |
||
| 211 | public function setOpType($opType) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get operation type. |
||
| 218 | * |
||
| 219 | * @return string |
||
| 220 | */ |
||
| 221 | public function getOpType() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return bool |
||
| 228 | */ |
||
| 229 | public function hasOpType() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Set routing query param. |
||
| 236 | * |
||
| 237 | * @param string $value routing |
||
| 238 | * |
||
| 239 | * @return $this |
||
| 240 | */ |
||
| 241 | public function setRouting($value) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Get routing parameter. |
||
| 248 | * |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | public function getRouting() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @return bool |
||
| 258 | */ |
||
| 259 | public function hasRouting() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param array|string $fields |
||
| 266 | * |
||
| 267 | * @return $this |
||
| 268 | */ |
||
| 269 | public function setFields($fields) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return $this |
||
| 280 | */ |
||
| 281 | public function setFieldsSource() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | public function getFields() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return bool |
||
| 296 | */ |
||
| 297 | public function hasFields() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param int $num |
||
| 304 | * |
||
| 305 | * @return $this |
||
| 306 | */ |
||
| 307 | public function setRetryOnConflict($num) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return int |
||
| 314 | */ |
||
| 315 | public function getRetryOnConflict() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @return bool |
||
| 322 | */ |
||
| 323 | public function hasRetryOnConflict() |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @param bool|string $refresh |
||
| 330 | * |
||
| 331 | * @return $this |
||
| 332 | */ |
||
| 333 | public function setRefresh($refresh = true) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return bool|string |
||
| 344 | */ |
||
| 345 | public function getRefresh() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return bool |
||
| 356 | */ |
||
| 357 | public function hasRefresh() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param string $timeout |
||
| 364 | * |
||
| 365 | * @return $this |
||
| 366 | */ |
||
| 367 | public function setTimeout($timeout) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return bool |
||
| 374 | */ |
||
| 375 | public function getTimeout() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return bool |
||
| 382 | */ |
||
| 383 | public function hasTimeout() |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @param string $timeout |
||
| 390 | * |
||
| 391 | * @return $this |
||
| 392 | */ |
||
| 393 | public function setConsistency($timeout) |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @return string |
||
| 400 | */ |
||
| 401 | public function getConsistency() |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @return bool |
||
| 408 | */ |
||
| 409 | public function hasConsistency() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @param string $timeout |
||
| 416 | * |
||
| 417 | * @return $this |
||
| 418 | */ |
||
| 419 | public function setReplication($timeout) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @return string |
||
| 426 | */ |
||
| 427 | public function getReplication() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return bool |
||
| 434 | */ |
||
| 435 | public function hasReplication() |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param array|Document $data |
||
| 442 | * |
||
| 443 | * @return $this |
||
| 444 | */ |
||
| 445 | public function setUpsert($data) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return Document |
||
| 455 | */ |
||
| 456 | public function getUpsert() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @return bool |
||
| 463 | */ |
||
| 464 | public function hasUpsert() |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @param array $fields if empty array all options will be returned |
||
| 471 | * |
||
| 472 | * @return array |
||
| 473 | */ |
||
| 474 | public function getOptions(array $fields = []) |
||
| 482 | } |
||
| 483 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.