Complex classes like UpdateSimpleProductPage 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 UpdateSimpleProductPage, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProductPageInterface |
||
| 29 | { |
||
| 30 | use ChecksCodeImmutability; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | public function nameItIn($name, $localeCode) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | public function specifyPrice($price) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | public function getAttributeValue($attribute) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | public function hasAttribute($attribute) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | public function selectMainTaxon(TaxonInterface $taxon) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritdoc} |
||
| 93 | */ |
||
| 94 | public function isMainTaxonChosen($taxonName) |
||
| 100 | |||
| 101 | public function disableTracking() |
||
| 105 | |||
| 106 | public function enableTracking() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | */ |
||
| 114 | public function isTracked() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | public function enableSlugModification($locale) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc} |
||
| 129 | */ |
||
| 130 | public function isImageWithCodeDisplayed($code) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * {@inheritdoc} |
||
| 148 | */ |
||
| 149 | public function attachImage($path, $code = null) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * {@inheritdoc} |
||
| 167 | */ |
||
| 168 | public function changeImageWithCode($code, $path) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * {@inheritdoc} |
||
| 178 | */ |
||
| 179 | public function removeImageWithCode($code) |
||
| 186 | |||
| 187 | public function removeFirstImage() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * {@inheritdoc} |
||
| 195 | */ |
||
| 196 | public function countImages() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * {@inheritdoc} |
||
| 205 | */ |
||
| 206 | public function isImageCodeDisabled() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * {@inheritdoc} |
||
| 213 | */ |
||
| 214 | public function isSlugReadOnlyIn($locale) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * {@inheritdoc} |
||
| 221 | */ |
||
| 222 | public function getValidationMessageForImage() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * {@inheritdoc} |
||
| 238 | */ |
||
| 239 | public function associateProducts(ProductAssociationTypeInterface $productAssociationType, array $productsNames) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * {@inheritdoc} |
||
| 268 | */ |
||
| 269 | public function hasAssociatedProduct($productName, ProductAssociationTypeInterface $productAssociationType) |
||
| 278 | |||
| 279 | /** |
||
| 280 | * {@inheritdoc} |
||
| 281 | */ |
||
| 282 | public function removeAssociatedProduct($productName, ProductAssociationTypeInterface $productAssociationType) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * {@inheritdoc} |
||
| 298 | */ |
||
| 299 | public function getPricingConfigurationForChannelAndCurrencyCalculator(ChannelInterface $channel, CurrencyInterface $currency) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritdoc} |
||
| 310 | */ |
||
| 311 | public function getSlug($locale) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * {@inheritdoc} |
||
| 320 | */ |
||
| 321 | public function specifySlugIn($slug, $locale) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * {@inheritdoc} |
||
| 330 | */ |
||
| 331 | public function activateLanguageTab($locale) |
||
| 342 | |||
| 343 | /** |
||
| 344 | * {@inheritdoc} |
||
| 345 | */ |
||
| 346 | protected function getElement($name, array $parameters = []) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * {@inheritdoc} |
||
| 357 | */ |
||
| 358 | protected function getCodeElement() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * {@inheritdoc} |
||
| 365 | */ |
||
| 366 | protected function getDefinedElements() |
||
| 388 | |||
| 389 | private function openTaxonBookmarks() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @param string $tabName |
||
| 396 | */ |
||
| 397 | private function clickTabIfItsNotActive($tabName) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param string $tabName |
||
| 407 | */ |
||
| 408 | private function clickTab($tabName) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @param string $code |
||
| 416 | * |
||
| 417 | * @return NodeElement |
||
| 418 | */ |
||
| 419 | private function getImageElementByCode($code) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return NodeElement[] |
||
| 433 | */ |
||
| 434 | private function getImageElements() |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @return NodeElement |
||
| 443 | */ |
||
| 444 | private function getLastImageElement() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return NodeElement |
||
| 455 | */ |
||
| 456 | private function getFirstImageElement() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * @param string $locale |
||
| 467 | */ |
||
| 468 | private function waitForSlugGenerationIfNecessary($locale) |
||
| 484 | } |
||
| 485 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.