Complex classes like ImportProcessor 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 ImportProcessor, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class ImportProcessor implements ImportProcessorInterface |
||
| 36 | { |
||
| 37 | |||
| 38 | /** |
||
| 39 | * A PDO connection initialized with the values from the Doctrine EntityManager. |
||
| 40 | * |
||
| 41 | * @var \PDO |
||
| 42 | */ |
||
| 43 | protected $connection; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The repository to access categories. |
||
| 47 | * |
||
| 48 | * @var \TechDivision\Import\Repositories\CategoryRepository |
||
| 49 | */ |
||
| 50 | protected $categoryRepository; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The repository to access category varchar values. |
||
| 54 | * |
||
| 55 | * @var \TechDivision\Import\Repositories\CategoryVarcharRepository |
||
| 56 | */ |
||
| 57 | protected $categoryVarcharRepository; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The repository to access EAV attributes. |
||
| 61 | * |
||
| 62 | * @var \TechDivision\Import\Repositories\EavAttributeRepository |
||
| 63 | */ |
||
| 64 | protected $eavAttributeRepository; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The repository to access EAV attribute set. |
||
| 68 | * |
||
| 69 | * @var \TechDivision\Import\Repositories\EavAttributeSetRepository |
||
| 70 | */ |
||
| 71 | protected $eavAttributeSetRepository; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The repository to access stores. |
||
| 75 | * |
||
| 76 | * @var \TechDivision\Import\Repositories\StoreRepository |
||
| 77 | */ |
||
| 78 | protected $storeRepository; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The repository to access store websites. |
||
| 82 | * |
||
| 83 | * @var \TechDivision\Import\Repositories\StoreWebsiteRepository |
||
| 84 | */ |
||
| 85 | protected $storeWebsiteRepository; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The repository to access tax classes. |
||
| 89 | * |
||
| 90 | * @var \TechDivision\Import\Repositories\TaxClassRepository |
||
| 91 | */ |
||
| 92 | protected $taxClassRepository; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The repository to access link types. |
||
| 96 | * |
||
| 97 | * @var \TechDivision\Import\Repositories\LinkTypeRepository |
||
| 98 | */ |
||
| 99 | protected $linkTypeRepository; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The repository to access link attributes. |
||
| 103 | * |
||
| 104 | * @var \TechDivision\Import\Repositories\LinkAttributeRepository |
||
| 105 | */ |
||
| 106 | protected $linkAttributeRepository; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The repository to access the configuration. |
||
| 110 | * |
||
| 111 | * @var \TechDivision\Import\Repositories\CoreConfigDataRepository |
||
| 112 | */ |
||
| 113 | protected $coreConfigDataRepository; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Set's the passed connection. |
||
| 117 | * |
||
| 118 | * @param \PDO $connection The connection to set |
||
| 119 | * |
||
| 120 | * @return void |
||
| 121 | */ |
||
| 122 | public function setConnection(\PDO $connection) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Return's the connection. |
||
| 129 | * |
||
| 130 | * @return \PDO The connection instance |
||
| 131 | */ |
||
| 132 | public function getConnection() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
| 139 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
| 140 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
| 141 | * to autocommit mode. |
||
| 142 | * |
||
| 143 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 144 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
| 145 | */ |
||
| 146 | public function beginTransaction() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
| 153 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
| 154 | * |
||
| 155 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 156 | * @link http://php.net/manual/en/pdo.commit.php |
||
| 157 | */ |
||
| 158 | public function commit() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
| 165 | * |
||
| 166 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
| 167 | * rolled back the transaction. |
||
| 168 | * |
||
| 169 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
| 170 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
| 171 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
| 172 | * |
||
| 173 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 174 | * @link http://php.net/manual/en/pdo.rollback.php |
||
| 175 | */ |
||
| 176 | public function rollBack() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Set's the repository to access categories. |
||
| 183 | * |
||
| 184 | * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | public function setCategoryRepository($categoryRepository) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Return's the repository to access categories. |
||
| 195 | * |
||
| 196 | * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance |
||
| 197 | */ |
||
| 198 | public function getCategoryRepository() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Return's the repository to access category varchar values. |
||
| 205 | * |
||
| 206 | * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance |
||
| 207 | * |
||
| 208 | * @return void |
||
| 209 | */ |
||
| 210 | public function setCategoryVarcharRepository($categoryVarcharRepository) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Return's the repository to access category varchar values. |
||
| 217 | * |
||
| 218 | * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance |
||
| 219 | */ |
||
| 220 | public function getCategoryVarcharRepository() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Set's the repository to access EAV attributes. |
||
| 227 | * |
||
| 228 | * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes |
||
| 229 | * |
||
| 230 | * @return void |
||
| 231 | */ |
||
| 232 | public function setEavAttributeRepository($eavAttributeRepository) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Return's the repository to access EAV attributes. |
||
| 239 | * |
||
| 240 | * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance |
||
| 241 | */ |
||
| 242 | public function getEavAttributeRepository() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set's the repository to access EAV attribute sets. |
||
| 249 | * |
||
| 250 | * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets |
||
| 251 | * |
||
| 252 | * @return void |
||
| 253 | */ |
||
| 254 | public function setEavAttributeSetRepository($eavAttributeSetRepository) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Return's the repository to access EAV attribute sets. |
||
| 261 | * |
||
| 262 | * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance |
||
| 263 | */ |
||
| 264 | public function getEavAttributeSetRepository() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Set's the repository to access stores. |
||
| 271 | * |
||
| 272 | * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores |
||
| 273 | * |
||
| 274 | * @return void |
||
| 275 | */ |
||
| 276 | public function setStoreRepository($storeRepository) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Return's the repository to access stores. |
||
| 283 | * |
||
| 284 | * @return \TechDivision\Import\Repositories\StoreRepository The repository instance |
||
| 285 | */ |
||
| 286 | public function getStoreRepository() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Set's the repository to access store websites. |
||
| 293 | * |
||
| 294 | * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites |
||
| 295 | * |
||
| 296 | * @return void |
||
| 297 | */ |
||
| 298 | public function setStoreWebsiteRepository($storeWebsiteRepository) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Return's the repository to access store websites. |
||
| 305 | * |
||
| 306 | * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance |
||
| 307 | */ |
||
| 308 | public function getStoreWebsiteRepository() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Set's the repository to access tax classes. |
||
| 315 | * |
||
| 316 | * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores |
||
| 317 | * |
||
| 318 | * @return void |
||
| 319 | */ |
||
| 320 | public function setTaxClassRepository($taxClassRepository) |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Return's the repository to access tax classes. |
||
| 327 | * |
||
| 328 | * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance |
||
| 329 | */ |
||
| 330 | public function getTaxClassRepository() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Set's the repository to access link types. |
||
| 337 | * |
||
| 338 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types |
||
| 339 | * |
||
| 340 | * @return void |
||
| 341 | */ |
||
| 342 | public function setLinkTypeRepository($linkTypeRepository) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Return's the repository to access link types. |
||
| 349 | * |
||
| 350 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 351 | */ |
||
| 352 | public function getLinkTypeRepository() |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Set's the repository to access link attributes. |
||
| 359 | * |
||
| 360 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes |
||
| 361 | * |
||
| 362 | * @return void |
||
| 363 | */ |
||
| 364 | public function setLinkAttributeRepository($linkAttributeRepository) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Return's the repository to access link attributes. |
||
| 371 | * |
||
| 372 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 373 | */ |
||
| 374 | public function getLinkAttributeRepository() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Set's the repository to access the Magento 2 configuration. |
||
| 381 | * |
||
| 382 | * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration |
||
| 383 | * |
||
| 384 | * @return void |
||
| 385 | */ |
||
| 386 | public function setCoreConfigDataRepository($coreConfigDataRepository) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Return's the repository to access the Magento 2 configuration. |
||
| 393 | * |
||
| 394 | * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance |
||
| 395 | */ |
||
| 396 | public function getCoreConfigDataRepository() |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Return's the EAV attribute set with the passed ID. |
||
| 403 | * |
||
| 404 | * @param integer $id The ID of the EAV attribute set to load |
||
| 405 | * |
||
| 406 | * @return array The EAV attribute set |
||
| 407 | */ |
||
| 408 | public function getEavAttributeSet($id) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Return's the attribute sets for the passed entity type ID. |
||
| 415 | * |
||
| 416 | * @param mixed $entityTypeId The entity type ID to return the attribute sets for |
||
| 417 | * |
||
| 418 | * @return array|boolean The attribute sets for the passed entity type ID |
||
| 419 | */ |
||
| 420 | public function getEavAttributeSetsByEntityTypeId($entityTypeId) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Return's an array with the EAV attributes for the passed entity type ID and attribute set name. |
||
| 427 | * |
||
| 428 | * @param integer $entityTypeId The entity type ID of the EAV attributes to return |
||
| 429 | * @param string $attributeSetName The attribute set name of the EAV attributes to return |
||
| 430 | * |
||
| 431 | * @return array The |
||
| 432 | */ |
||
| 433 | public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Return's an array with the available EAV attributes for the passed option value and store ID. |
||
| 440 | * |
||
| 441 | * @param string $optionValue The option value of the EAV attributes |
||
| 442 | * @param string $storeId The store ID of the EAV attribues |
||
| 443 | * |
||
| 444 | * @return array The array with all available EAV attributes |
||
| 445 | */ |
||
| 446 | public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Return's the first EAV attribute for the passed option value and store ID. |
||
| 453 | * |
||
| 454 | * @param string $optionValue The option value of the EAV attributes |
||
| 455 | * @param string $storeId The store ID of the EAV attribues |
||
| 456 | * |
||
| 457 | * @return array The array with the EAV attribute |
||
| 458 | */ |
||
| 459 | public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Return's an array with the available EAV attributes for the passed is user defined flag. |
||
| 466 | * |
||
| 467 | * @param integer $isUserDefined The flag itself |
||
| 468 | * |
||
| 469 | * @return array The array with the EAV attributes matching the passed flag |
||
| 470 | */ |
||
| 471 | public function getEavAttributeByIsUserDefined($isUserDefined = 1) |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Return's an array with the available stores. |
||
| 478 | * |
||
| 479 | * @return array The array with the available stores |
||
| 480 | */ |
||
| 481 | public function getStores() |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Return's the default store. |
||
| 488 | * |
||
| 489 | * @return array The default store |
||
| 490 | */ |
||
| 491 | public function getDefaultStore() |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Return's an array with the available store websites. |
||
| 498 | * |
||
| 499 | * @return array The array with the available store websites |
||
| 500 | */ |
||
| 501 | public function getStoreWebsites() |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Return's an array with the available tax classes. |
||
| 508 | * |
||
| 509 | * @return array The array with the available tax classes |
||
| 510 | */ |
||
| 511 | public function getTaxClasses() |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Return's an array with all available categories. |
||
| 518 | * |
||
| 519 | * @return array The available categories |
||
| 520 | */ |
||
| 521 | public function getCategories() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Return's an array with the root categories with the store code as key. |
||
| 528 | * |
||
| 529 | * @return array The root categories |
||
| 530 | */ |
||
| 531 | public function getRootCategories() |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Returns the category varchar values for the categories with |
||
| 538 | * the passed with the passed entity IDs. |
||
| 539 | * |
||
| 540 | * @param array $entityIds The array with the category IDs |
||
| 541 | * |
||
| 542 | * @return mixed The category varchar values |
||
| 543 | */ |
||
| 544 | public function getCategoryVarcharsByEntityIds(array $entityIds) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Return's an array with all available link types. |
||
| 551 | * |
||
| 552 | * @return array The available link types |
||
| 553 | */ |
||
| 554 | public function getLinkTypes() |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Return's an array with all available link attributes. |
||
| 561 | * |
||
| 562 | * @return array The available link attributes |
||
| 563 | */ |
||
| 564 | public function getLinkAttributes() |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Return's an array with the Magento 2 configuration. |
||
| 571 | * |
||
| 572 | * @return array The Magento 2 configuration |
||
| 573 | */ |
||
| 574 | public function getCoreConfigData() |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Returns the array with the global data necessary for the |
||
| 581 | * import process. |
||
| 582 | * |
||
| 583 | * @return array The array with the global data |
||
| 584 | */ |
||
| 585 | public function getGlobalData() |
||
| 641 | } |
||
| 642 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..