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 \Elastica\Document |
||
| 15 | */ |
||
| 16 | protected $_upsert; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Sets the id of the document. |
||
| 20 | * |
||
| 21 | * @param string|int $id |
||
| 22 | * |
||
| 23 | * @return $this |
||
| 24 | */ |
||
| 25 | public function setId($id) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Returns document id. |
||
| 32 | * |
||
| 33 | * @return string|int Document id |
||
| 34 | */ |
||
| 35 | public function getId() |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return bool |
||
| 42 | */ |
||
| 43 | public function hasId() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Sets the document type name. |
||
| 50 | * |
||
| 51 | * @param Type|string $type Type name |
||
| 52 | * |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | public function setType($type) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Return document type name. |
||
| 67 | * |
||
| 68 | * @throws \Elastica\Exception\InvalidException |
||
| 69 | * |
||
| 70 | * @return string Document type name |
||
| 71 | */ |
||
| 72 | public function getType() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Sets the document index name. |
||
| 79 | * |
||
| 80 | * @param Index|string $index Index name |
||
| 81 | * |
||
| 82 | * @return $this |
||
| 83 | */ |
||
| 84 | public function setIndex($index) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Get the document index name. |
||
| 95 | * |
||
| 96 | * @throws \Elastica\Exception\InvalidException |
||
| 97 | * |
||
| 98 | * @return string Index name |
||
| 99 | */ |
||
| 100 | public function getIndex() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Sets the version of a document for use with optimistic concurrency control. |
||
| 107 | * |
||
| 108 | * @param int $version Document version |
||
| 109 | * |
||
| 110 | * @return $this |
||
| 111 | * |
||
| 112 | * @see https://www.elastic.co/blog/versioning |
||
| 113 | */ |
||
| 114 | public function setVersion($version) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Returns document version. |
||
| 121 | * |
||
| 122 | * @return string|int Document version |
||
| 123 | */ |
||
| 124 | public function getVersion() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return bool |
||
| 131 | */ |
||
| 132 | public function hasVersion() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Sets the version_type of a document |
||
| 139 | * Default in ES is internal, but you can set to external to use custom versioning. |
||
| 140 | * |
||
| 141 | * @param string $versionType Document version type |
||
| 142 | * |
||
| 143 | * @return $this |
||
| 144 | */ |
||
| 145 | public function setVersionType($versionType) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Returns document version type. |
||
| 152 | * |
||
| 153 | * @return string|int Document version type |
||
| 154 | */ |
||
| 155 | public function getVersionType() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | public function hasVersionType() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Set operation type. |
||
| 170 | * |
||
| 171 | * @param string $opType Only accept create |
||
| 172 | * |
||
| 173 | * @return $this |
||
| 174 | */ |
||
| 175 | public function setOpType($opType) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Get operation type. |
||
| 182 | * |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function getOpType() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return bool |
||
| 192 | */ |
||
| 193 | public function hasOpType() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Set routing query param. |
||
| 200 | * |
||
| 201 | * @param string $value routing |
||
| 202 | * |
||
| 203 | * @return $this |
||
| 204 | */ |
||
| 205 | public function setRouting($value) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Get routing parameter. |
||
| 212 | * |
||
| 213 | * @return string |
||
| 214 | */ |
||
| 215 | public function getRouting() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return bool |
||
| 222 | */ |
||
| 223 | public function hasRouting() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @param array|string $fields |
||
| 230 | * |
||
| 231 | * @return $this |
||
| 232 | */ |
||
| 233 | public function setFields($fields) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return $this |
||
| 244 | */ |
||
| 245 | public function setFieldsSource() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | public function getFields() |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return bool |
||
| 260 | */ |
||
| 261 | public function hasFields() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param int $num |
||
| 268 | * |
||
| 269 | * @return $this |
||
| 270 | */ |
||
| 271 | public function setRetryOnConflict($num) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @return int |
||
| 278 | */ |
||
| 279 | public function getRetryOnConflict() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @return bool |
||
| 286 | */ |
||
| 287 | public function hasRetryOnConflict() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @param bool $refresh |
||
| 294 | * |
||
| 295 | * @return $this |
||
| 296 | */ |
||
| 297 | public function setRefresh($refresh = true) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @return bool |
||
| 304 | */ |
||
| 305 | public function getRefresh() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return bool |
||
| 312 | */ |
||
| 313 | public function hasRefresh() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param string $timeout |
||
| 320 | * |
||
| 321 | * @return $this |
||
| 322 | */ |
||
| 323 | public function setTimeout($timeout) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @return bool |
||
| 330 | */ |
||
| 331 | public function getTimeout() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @return bool |
||
| 338 | */ |
||
| 339 | public function hasTimeout() |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @param string $timeout |
||
| 346 | * |
||
| 347 | * @return $this |
||
| 348 | */ |
||
| 349 | public function setConsistency($timeout) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return string |
||
| 356 | */ |
||
| 357 | public function getConsistency() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return bool |
||
| 364 | */ |
||
| 365 | public function hasConsistency() |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @param string $timeout |
||
| 372 | * |
||
| 373 | * @return $this |
||
| 374 | */ |
||
| 375 | public function setReplication($timeout) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return string |
||
| 382 | */ |
||
| 383 | public function getReplication() |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @return bool |
||
| 390 | */ |
||
| 391 | public function hasReplication() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param \Elastica\Document|array $data |
||
| 398 | * |
||
| 399 | * @return $this |
||
| 400 | */ |
||
| 401 | public function setUpsert($data) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return \Elastica\Document |
||
| 411 | */ |
||
| 412 | public function getUpsert() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @return bool |
||
| 419 | */ |
||
| 420 | public function hasUpsert() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @param array $fields if empty array all options will be returned |
||
| 427 | * |
||
| 428 | * @return array |
||
| 429 | */ |
||
| 430 | public function getOptions(array $fields = []) |
||
| 438 | } |
||
| 439 |