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 category assembler instance. |
||
| 47 | * |
||
| 48 | * @var \TechDivision\Import\Assembler\CategoryAssembler |
||
| 49 | */ |
||
| 50 | protected $categoryAssembler; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The repository to access categories. |
||
| 54 | * |
||
| 55 | * @var \TechDivision\Import\Repositories\CategoryRepository |
||
| 56 | */ |
||
| 57 | protected $categoryRepository; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The repository to access category varchar values. |
||
| 61 | * |
||
| 62 | * @var \TechDivision\Import\Repositories\CategoryVarcharRepository |
||
| 63 | */ |
||
| 64 | protected $categoryVarcharRepository; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The repository to access EAV attributes. |
||
| 68 | * |
||
| 69 | * @var \TechDivision\Import\Repositories\EavAttributeRepository |
||
| 70 | */ |
||
| 71 | protected $eavAttributeRepository; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The repository to access EAV attribute set. |
||
| 75 | * |
||
| 76 | * @var \TechDivision\Import\Repositories\EavAttributeSetRepository |
||
| 77 | */ |
||
| 78 | protected $eavAttributeSetRepository; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The repository to access EAV entity types. |
||
| 82 | * |
||
| 83 | * @var \TechDivision\Import\Repositories\EavEntityTypeRepository |
||
| 84 | */ |
||
| 85 | protected $eavEntityTypeRepository; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The repository to access stores. |
||
| 89 | * |
||
| 90 | * @var \TechDivision\Import\Repositories\StoreRepository |
||
| 91 | */ |
||
| 92 | protected $storeRepository; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The repository to access store websites. |
||
| 96 | * |
||
| 97 | * @var \TechDivision\Import\Repositories\StoreWebsiteRepository |
||
| 98 | */ |
||
| 99 | protected $storeWebsiteRepository; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The repository to access tax classes. |
||
| 103 | * |
||
| 104 | * @var \TechDivision\Import\Repositories\TaxClassRepository |
||
| 105 | */ |
||
| 106 | protected $taxClassRepository; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The repository to access link types. |
||
| 110 | * |
||
| 111 | * @var \TechDivision\Import\Repositories\LinkTypeRepository |
||
| 112 | */ |
||
| 113 | protected $linkTypeRepository; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * The repository to access link attributes. |
||
| 117 | * |
||
| 118 | * @var \TechDivision\Import\Repositories\LinkAttributeRepository |
||
| 119 | */ |
||
| 120 | protected $linkAttributeRepository; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The repository to access the configuration. |
||
| 124 | * |
||
| 125 | * @var \TechDivision\Import\Repositories\CoreConfigDataRepository |
||
| 126 | */ |
||
| 127 | protected $coreConfigDataRepository; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Set's the passed connection. |
||
| 131 | * |
||
| 132 | * @param \PDO $connection The connection to set |
||
| 133 | * |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | public function setConnection(\PDO $connection) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Return's the connection. |
||
| 143 | * |
||
| 144 | * @return \PDO The connection instance |
||
| 145 | */ |
||
| 146 | public function getConnection() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
| 153 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
| 154 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
| 155 | * to autocommit mode. |
||
| 156 | * |
||
| 157 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 158 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
| 159 | */ |
||
| 160 | public function beginTransaction() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
| 167 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
| 168 | * |
||
| 169 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 170 | * @link http://php.net/manual/en/pdo.commit.php |
||
| 171 | */ |
||
| 172 | public function commit() |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
| 179 | * |
||
| 180 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
| 181 | * rolled back the transaction. |
||
| 182 | * |
||
| 183 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
| 184 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
| 185 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
| 186 | * |
||
| 187 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 188 | * @link http://php.net/manual/en/pdo.rollback.php |
||
| 189 | */ |
||
| 190 | public function rollBack() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Set's the category assembler. |
||
| 197 | * |
||
| 198 | * @param \TechDivision\Import\Assembler\CategoryAssembler $categoryAssembler The category assembler |
||
| 199 | * |
||
| 200 | * @return void |
||
| 201 | */ |
||
| 202 | public function setCategoryAssembler($categoryAssembler) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Return's the category assembler. |
||
| 209 | * |
||
| 210 | * @return \TechDivision\Import\Assembler\CategoryAssembler The category assembler instance |
||
| 211 | */ |
||
| 212 | public function getCategoryAssembler() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Set's the repository to access categories. |
||
| 219 | * |
||
| 220 | * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories |
||
| 221 | * |
||
| 222 | * @return void |
||
| 223 | */ |
||
| 224 | public function setCategoryRepository($categoryRepository) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Return's the repository to access categories. |
||
| 231 | * |
||
| 232 | * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance |
||
| 233 | */ |
||
| 234 | public function getCategoryRepository() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Return's the repository to access category varchar values. |
||
| 241 | * |
||
| 242 | * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance |
||
| 243 | * |
||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | public function setCategoryVarcharRepository($categoryVarcharRepository) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Return's the repository to access category varchar values. |
||
| 253 | * |
||
| 254 | * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance |
||
| 255 | */ |
||
| 256 | public function getCategoryVarcharRepository() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Set's the repository to access EAV attributes. |
||
| 263 | * |
||
| 264 | * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes |
||
| 265 | * |
||
| 266 | * @return void |
||
| 267 | */ |
||
| 268 | public function setEavAttributeRepository($eavAttributeRepository) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Return's the repository to access EAV attributes. |
||
| 275 | * |
||
| 276 | * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance |
||
| 277 | */ |
||
| 278 | public function getEavAttributeRepository() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Set's the repository to access EAV attribute sets. |
||
| 285 | * |
||
| 286 | * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets |
||
| 287 | * |
||
| 288 | * @return void |
||
| 289 | */ |
||
| 290 | public function setEavAttributeSetRepository($eavAttributeSetRepository) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Return's the repository to access EAV attribute sets. |
||
| 297 | * |
||
| 298 | * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance |
||
| 299 | */ |
||
| 300 | public function getEavAttributeSetRepository() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Return's the repository to access EAV entity types. |
||
| 307 | * |
||
| 308 | * @return \TechDivision\Import\Repositories\EavEntityTypeRepository The repository instance |
||
| 309 | */ |
||
| 310 | public function getEavEntityTypeRepository() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Set's the repository to access EAV entity types. |
||
| 317 | * |
||
| 318 | * @param \TechDivision\Import\Repositories\EavEntityTypeRepository $eavEntityTypeRepository The repository the access EAV entity types |
||
| 319 | * |
||
| 320 | * @return void |
||
| 321 | */ |
||
| 322 | public function setEavEntityTypeRepository($eavEntityTypeRepository) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Set's the repository to access stores. |
||
| 329 | * |
||
| 330 | * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores |
||
| 331 | * |
||
| 332 | * @return void |
||
| 333 | */ |
||
| 334 | public function setStoreRepository($storeRepository) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Return's the repository to access stores. |
||
| 341 | * |
||
| 342 | * @return \TechDivision\Import\Repositories\StoreRepository The repository instance |
||
| 343 | */ |
||
| 344 | public function getStoreRepository() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Set's the repository to access store websites. |
||
| 351 | * |
||
| 352 | * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites |
||
| 353 | * |
||
| 354 | * @return void |
||
| 355 | */ |
||
| 356 | public function setStoreWebsiteRepository($storeWebsiteRepository) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Return's the repository to access store websites. |
||
| 363 | * |
||
| 364 | * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance |
||
| 365 | */ |
||
| 366 | public function getStoreWebsiteRepository() |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Set's the repository to access tax classes. |
||
| 373 | * |
||
| 374 | * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores |
||
| 375 | * |
||
| 376 | * @return void |
||
| 377 | */ |
||
| 378 | public function setTaxClassRepository($taxClassRepository) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Return's the repository to access tax classes. |
||
| 385 | * |
||
| 386 | * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance |
||
| 387 | */ |
||
| 388 | public function getTaxClassRepository() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Set's the repository to access link types. |
||
| 395 | * |
||
| 396 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types |
||
| 397 | * |
||
| 398 | * @return void |
||
| 399 | */ |
||
| 400 | public function setLinkTypeRepository($linkTypeRepository) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Return's the repository to access link types. |
||
| 407 | * |
||
| 408 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 409 | */ |
||
| 410 | public function getLinkTypeRepository() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Set's the repository to access link attributes. |
||
| 417 | * |
||
| 418 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes |
||
| 419 | * |
||
| 420 | * @return void |
||
| 421 | */ |
||
| 422 | public function setLinkAttributeRepository($linkAttributeRepository) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Return's the repository to access link attributes. |
||
| 429 | * |
||
| 430 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 431 | */ |
||
| 432 | public function getLinkAttributeRepository() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Set's the repository to access the Magento 2 configuration. |
||
| 439 | * |
||
| 440 | * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration |
||
| 441 | * |
||
| 442 | * @return void |
||
| 443 | */ |
||
| 444 | public function setCoreConfigDataRepository($coreConfigDataRepository) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Return's the repository to access the Magento 2 configuration. |
||
| 451 | * |
||
| 452 | * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance |
||
| 453 | */ |
||
| 454 | public function getCoreConfigDataRepository() |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Return's the EAV attribute set with the passed ID. |
||
| 461 | * |
||
| 462 | * @param integer $id The ID of the EAV attribute set to load |
||
| 463 | * |
||
| 464 | * @return array The EAV attribute set |
||
| 465 | */ |
||
| 466 | public function getEavAttributeSet($id) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Return's the attribute sets for the passed entity type ID. |
||
| 473 | * |
||
| 474 | * @param mixed $entityTypeId The entity type ID to return the attribute sets for |
||
| 475 | * |
||
| 476 | * @return array|boolean The attribute sets for the passed entity type ID |
||
| 477 | */ |
||
| 478 | public function getEavAttributeSetsByEntityTypeId($entityTypeId) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Return's an array with the EAV attributes for the passed entity type ID and attribute set name. |
||
| 485 | * |
||
| 486 | * @param integer $entityTypeId The entity type ID of the EAV attributes to return |
||
| 487 | * @param string $attributeSetName The attribute set name of the EAV attributes to return |
||
| 488 | * |
||
| 489 | * @return array The |
||
| 490 | */ |
||
| 491 | public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Return's an array with the available EAV attributes for the passed option value and store ID. |
||
| 498 | * |
||
| 499 | * @param string $optionValue The option value of the EAV attributes |
||
| 500 | * @param string $storeId The store ID of the EAV attribues |
||
| 501 | * |
||
| 502 | * @return array The array with all available EAV attributes |
||
| 503 | */ |
||
| 504 | public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId) |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Return's the first EAV attribute for the passed option value and store ID. |
||
| 511 | * |
||
| 512 | * @param string $optionValue The option value of the EAV attributes |
||
| 513 | * @param string $storeId The store ID of the EAV attribues |
||
| 514 | * |
||
| 515 | * @return array The array with the EAV attribute |
||
| 516 | */ |
||
| 517 | public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId) |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Return's an array with the available EAV attributes for the passed is user defined flag. |
||
| 524 | * |
||
| 525 | * @param integer $isUserDefined The flag itself |
||
| 526 | * |
||
| 527 | * @return array The array with the EAV attributes matching the passed flag |
||
| 528 | */ |
||
| 529 | public function getEavAttributesByIsUserDefined($isUserDefined = 1) |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Return's an array with the available EAV attributes for the passed is entity type and |
||
| 536 | * user defined flag. |
||
| 537 | * |
||
| 538 | * @param integer $entityTypeId The entity type ID of the EAV attributes to return |
||
| 539 | * @param integer $isUserDefined The flag itself |
||
| 540 | * |
||
| 541 | * @return array The array with the EAV attributes matching the passed entity type and user defined flag |
||
| 542 | */ |
||
| 543 | public function getEavAttributesByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined = 1) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Return's an array with all available EAV entity types with the entity type code as key. |
||
| 550 | * |
||
| 551 | * @return array The available link types |
||
| 552 | */ |
||
| 553 | public function getEavEntityTypes() |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Return's an array with the available stores. |
||
| 560 | * |
||
| 561 | * @return array The array with the available stores |
||
| 562 | */ |
||
| 563 | public function getStores() |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Return's the default store. |
||
| 570 | * |
||
| 571 | * @return array The default store |
||
| 572 | */ |
||
| 573 | public function getDefaultStore() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Return's an array with the available store websites. |
||
| 580 | * |
||
| 581 | * @return array The array with the available store websites |
||
| 582 | */ |
||
| 583 | public function getStoreWebsites() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Return's an array with the available tax classes. |
||
| 590 | * |
||
| 591 | * @return array The array with the available tax classes |
||
| 592 | */ |
||
| 593 | public function getTaxClasses() |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Return's an array with all available categories. |
||
| 600 | * |
||
| 601 | * @return array The available categories |
||
| 602 | */ |
||
| 603 | public function getCategories() |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Return's an array with the root categories with the store code as key. |
||
| 610 | * |
||
| 611 | * @return array The root categories |
||
| 612 | */ |
||
| 613 | public function getRootCategories() |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Returns the category varchar values for the categories with |
||
| 620 | * the passed with the passed entity IDs. |
||
| 621 | * |
||
| 622 | * @param array $entityIds The array with the category IDs |
||
| 623 | * |
||
| 624 | * @return mixed The category varchar values |
||
| 625 | */ |
||
| 626 | public function getCategoryVarcharsByEntityIds(array $entityIds) |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Return's an array with all available link types. |
||
| 633 | * |
||
| 634 | * @return array The available link types |
||
| 635 | */ |
||
| 636 | public function getLinkTypes() |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Return's an array with all available link attributes. |
||
| 643 | * |
||
| 644 | * @return array The available link attributes |
||
| 645 | */ |
||
| 646 | public function getLinkAttributes() |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Return's an array with the Magento 2 configuration. |
||
| 653 | * |
||
| 654 | * @return array The Magento 2 configuration |
||
| 655 | */ |
||
| 656 | public function getCoreConfigData() |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Returns the array with the global data necessary for the |
||
| 663 | * import process. |
||
| 664 | * |
||
| 665 | * @return array The array with the global data |
||
| 666 | */ |
||
| 667 | public function getGlobalData() |
||
| 725 | } |
||
| 726 |
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..