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 |
||
| 26 | class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProductPageInterface |
||
| 27 | { |
||
| 28 | use ChecksCodeImmutability; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | public function nameItIn($name, $localeCode) |
||
| 34 | { |
||
| 35 | $this->getDocument()->fillField( |
||
| 36 | sprintf('sylius_product_translations_%s_name', $localeCode), $name |
||
| 37 | ); |
||
| 38 | |||
| 39 | $this->waitForSlugGenerationIfNecessary(); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | public function specifyPrice($price) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | public function getAttributeValue($attribute) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | public function hasAttribute($attribute) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | public function selectMainTaxon(TaxonInterface $taxon) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * {@inheritdoc} |
||
| 92 | */ |
||
| 93 | public function isMainTaxonChosen($taxonName) |
||
| 99 | |||
| 100 | public function disableTracking() |
||
| 104 | |||
| 105 | public function enableTracking() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * {@inheritdoc} |
||
| 112 | */ |
||
| 113 | public function isTracked() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * {@inheritdoc} |
||
| 120 | */ |
||
| 121 | public function isImageWithCodeDisplayed($code) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | */ |
||
| 140 | public function attachImage($path, $code = null) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | public function changeImageWithCode($code, $path) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * {@inheritdoc} |
||
| 169 | */ |
||
| 170 | public function removeImageWithCode($code) |
||
| 177 | |||
| 178 | public function removeFirstImage() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * {@inheritdoc} |
||
| 186 | */ |
||
| 187 | public function countImages() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * {@inheritdoc} |
||
| 196 | */ |
||
| 197 | public function isImageCodeDisabled() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * {@inheritdoc} |
||
| 204 | */ |
||
| 205 | public function isSlugReadOnly() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * {@inheritdoc} |
||
| 212 | */ |
||
| 213 | public function getValidationMessageForImage() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * {@inheritdoc} |
||
| 229 | */ |
||
| 230 | public function associateProducts(ProductAssociationTypeInterface $productAssociationType, array $productsNames) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * {@inheritdoc} |
||
| 258 | */ |
||
| 259 | public function hasAssociatedProduct($productName, ProductAssociationTypeInterface $productAssociationType) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * {@inheritdoc} |
||
| 271 | */ |
||
| 272 | public function removeAssociatedProduct($productName, ProductAssociationTypeInterface $productAssociationType) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * {@inheritdoc} |
||
| 288 | */ |
||
| 289 | protected function getCodeElement() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * {@inheritdoc} |
||
| 296 | */ |
||
| 297 | protected function getDefinedElements() |
||
| 316 | |||
| 317 | private function openTaxonBookmarks() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @param string $tabName |
||
| 324 | */ |
||
| 325 | private function clickTabIfItsNotActive($tabName) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param string $tabName |
||
| 335 | */ |
||
| 336 | private function clickTab($tabName) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @param string $code |
||
| 344 | * |
||
| 345 | * @return NodeElement |
||
| 346 | */ |
||
| 347 | private function getImageElementByCode($code) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @return NodeElement[] |
||
| 361 | */ |
||
| 362 | private function getImageElements() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @return NodeElement |
||
| 371 | */ |
||
| 372 | private function getLastImageElement() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @return NodeElement |
||
| 383 | */ |
||
| 384 | private function getFirstImageElement() |
||
| 392 | |||
| 393 | private function waitForSlugGenerationIfNecessary() |
||
| 409 | } |
||
| 410 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.