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 | * Initialize the processor with the necessary assembler and repository instances. |
||
| 131 | * |
||
| 132 | * @param \PDO $connection The PDO connection to use |
||
| 133 | * @param \TechDivision\Import\Assembler\CategoryAssembler $categoryAssembler The category assembler instance |
||
| 134 | * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories |
||
| 135 | * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository to access category varchar values |
||
| 136 | * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes |
||
| 137 | * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository to access EAV attribute set |
||
| 138 | * @param \TechDivision\Import\Repositories\EavEntityTypeRepository $eavEntityTypeRepository The repository to access EAV entity types |
||
| 139 | * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository to access stores |
||
| 140 | * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository to access store websites |
||
| 141 | * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository to access tax classes |
||
| 142 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types |
||
| 143 | * @param \TechDivision\Import\Repositories\LinkAttributeRepository $linkAttributeRepository The repository to access link attributes |
||
| 144 | * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the configuration |
||
| 145 | */ |
||
| 146 | public function __construct( |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Set's the passed connection. |
||
| 178 | * |
||
| 179 | * @param \PDO $connection The connection to set |
||
| 180 | * |
||
| 181 | * @return void |
||
| 182 | */ |
||
| 183 | public function setConnection(\PDO $connection) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Return's the connection. |
||
| 190 | * |
||
| 191 | * @return \PDO The connection instance |
||
| 192 | */ |
||
| 193 | public function getConnection() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
| 200 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
| 201 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
| 202 | * to autocommit mode. |
||
| 203 | * |
||
| 204 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 205 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
| 206 | */ |
||
| 207 | public function beginTransaction() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
| 214 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
| 215 | * |
||
| 216 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 217 | * @link http://php.net/manual/en/pdo.commit.php |
||
| 218 | */ |
||
| 219 | public function commit() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
| 226 | * |
||
| 227 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
| 228 | * rolled back the transaction. |
||
| 229 | * |
||
| 230 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
| 231 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
| 232 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
| 233 | * |
||
| 234 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 235 | * @link http://php.net/manual/en/pdo.rollback.php |
||
| 236 | */ |
||
| 237 | public function rollBack() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Set's the category assembler. |
||
| 244 | * |
||
| 245 | * @param \TechDivision\Import\Assembler\CategoryAssembler $categoryAssembler The category assembler |
||
| 246 | * |
||
| 247 | * @return void |
||
| 248 | */ |
||
| 249 | public function setCategoryAssembler($categoryAssembler) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Return's the category assembler. |
||
| 256 | * |
||
| 257 | * @return \TechDivision\Import\Assembler\CategoryAssembler The category assembler instance |
||
| 258 | */ |
||
| 259 | public function getCategoryAssembler() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Set's the repository to access categories. |
||
| 266 | * |
||
| 267 | * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories |
||
| 268 | * |
||
| 269 | * @return void |
||
| 270 | */ |
||
| 271 | public function setCategoryRepository($categoryRepository) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Return's the repository to access categories. |
||
| 278 | * |
||
| 279 | * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance |
||
| 280 | */ |
||
| 281 | public function getCategoryRepository() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Return's the repository to access category varchar values. |
||
| 288 | * |
||
| 289 | * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance |
||
| 290 | * |
||
| 291 | * @return void |
||
| 292 | */ |
||
| 293 | public function setCategoryVarcharRepository($categoryVarcharRepository) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Return's the repository to access category varchar values. |
||
| 300 | * |
||
| 301 | * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance |
||
| 302 | */ |
||
| 303 | public function getCategoryVarcharRepository() |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Set's the repository to access EAV attributes. |
||
| 310 | * |
||
| 311 | * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes |
||
| 312 | * |
||
| 313 | * @return void |
||
| 314 | */ |
||
| 315 | public function setEavAttributeRepository($eavAttributeRepository) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Return's the repository to access EAV attributes. |
||
| 322 | * |
||
| 323 | * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance |
||
| 324 | */ |
||
| 325 | public function getEavAttributeRepository() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Set's the repository to access EAV attribute sets. |
||
| 332 | * |
||
| 333 | * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets |
||
| 334 | * |
||
| 335 | * @return void |
||
| 336 | */ |
||
| 337 | public function setEavAttributeSetRepository($eavAttributeSetRepository) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Return's the repository to access EAV attribute sets. |
||
| 344 | * |
||
| 345 | * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance |
||
| 346 | */ |
||
| 347 | public function getEavAttributeSetRepository() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Return's the repository to access EAV entity types. |
||
| 354 | * |
||
| 355 | * @return \TechDivision\Import\Repositories\EavEntityTypeRepository The repository instance |
||
| 356 | */ |
||
| 357 | public function getEavEntityTypeRepository() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Set's the repository to access EAV entity types. |
||
| 364 | * |
||
| 365 | * @param \TechDivision\Import\Repositories\EavEntityTypeRepository $eavEntityTypeRepository The repository the access EAV entity types |
||
| 366 | * |
||
| 367 | * @return void |
||
| 368 | */ |
||
| 369 | public function setEavEntityTypeRepository($eavEntityTypeRepository) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Set's the repository to access stores. |
||
| 376 | * |
||
| 377 | * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores |
||
| 378 | * |
||
| 379 | * @return void |
||
| 380 | */ |
||
| 381 | public function setStoreRepository($storeRepository) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Return's the repository to access stores. |
||
| 388 | * |
||
| 389 | * @return \TechDivision\Import\Repositories\StoreRepository The repository instance |
||
| 390 | */ |
||
| 391 | public function getStoreRepository() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Set's the repository to access store websites. |
||
| 398 | * |
||
| 399 | * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites |
||
| 400 | * |
||
| 401 | * @return void |
||
| 402 | */ |
||
| 403 | public function setStoreWebsiteRepository($storeWebsiteRepository) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Return's the repository to access store websites. |
||
| 410 | * |
||
| 411 | * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance |
||
| 412 | */ |
||
| 413 | public function getStoreWebsiteRepository() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Set's the repository to access tax classes. |
||
| 420 | * |
||
| 421 | * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores |
||
| 422 | * |
||
| 423 | * @return void |
||
| 424 | */ |
||
| 425 | public function setTaxClassRepository($taxClassRepository) |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Return's the repository to access tax classes. |
||
| 432 | * |
||
| 433 | * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance |
||
| 434 | */ |
||
| 435 | public function getTaxClassRepository() |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Set's the repository to access link types. |
||
| 442 | * |
||
| 443 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types |
||
| 444 | * |
||
| 445 | * @return void |
||
| 446 | */ |
||
| 447 | public function setLinkTypeRepository($linkTypeRepository) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Return's the repository to access link types. |
||
| 454 | * |
||
| 455 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 456 | */ |
||
| 457 | public function getLinkTypeRepository() |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Set's the repository to access link attributes. |
||
| 464 | * |
||
| 465 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes |
||
| 466 | * |
||
| 467 | * @return void |
||
| 468 | */ |
||
| 469 | public function setLinkAttributeRepository($linkAttributeRepository) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Return's the repository to access link attributes. |
||
| 476 | * |
||
| 477 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 478 | */ |
||
| 479 | public function getLinkAttributeRepository() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Set's the repository to access the Magento 2 configuration. |
||
| 486 | * |
||
| 487 | * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration |
||
| 488 | * |
||
| 489 | * @return void |
||
| 490 | */ |
||
| 491 | public function setCoreConfigDataRepository($coreConfigDataRepository) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Return's the repository to access the Magento 2 configuration. |
||
| 498 | * |
||
| 499 | * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance |
||
| 500 | */ |
||
| 501 | public function getCoreConfigDataRepository() |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Return's the EAV attribute set with the passed ID. |
||
| 508 | * |
||
| 509 | * @param integer $id The ID of the EAV attribute set to load |
||
| 510 | * |
||
| 511 | * @return array The EAV attribute set |
||
| 512 | */ |
||
| 513 | public function getEavAttributeSet($id) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Return's the attribute sets for the passed entity type ID. |
||
| 520 | * |
||
| 521 | * @param mixed $entityTypeId The entity type ID to return the attribute sets for |
||
| 522 | * |
||
| 523 | * @return array|boolean The attribute sets for the passed entity type ID |
||
| 524 | */ |
||
| 525 | public function getEavAttributeSetsByEntityTypeId($entityTypeId) |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Return's an array with the EAV attributes for the passed entity type ID and attribute set name. |
||
| 532 | * |
||
| 533 | * @param integer $entityTypeId The entity type ID of the EAV attributes to return |
||
| 534 | * @param string $attributeSetName The attribute set name of the EAV attributes to return |
||
| 535 | * |
||
| 536 | * @return array The |
||
| 537 | */ |
||
| 538 | public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Return's an array with the available EAV attributes for the passed option value and store ID. |
||
| 545 | * |
||
| 546 | * @param string $optionValue The option value of the EAV attributes |
||
| 547 | * @param string $storeId The store ID of the EAV attribues |
||
| 548 | * |
||
| 549 | * @return array The array with all available EAV attributes |
||
| 550 | */ |
||
| 551 | public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId) |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Return's the first EAV attribute for the passed option value and store ID. |
||
| 558 | * |
||
| 559 | * @param string $optionValue The option value of the EAV attributes |
||
| 560 | * @param string $storeId The store ID of the EAV attribues |
||
| 561 | * |
||
| 562 | * @return array The array with the EAV attribute |
||
| 563 | */ |
||
| 564 | public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId) |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Return's an array with the available EAV attributes for the passed is user defined flag. |
||
| 571 | * |
||
| 572 | * @param integer $isUserDefined The flag itself |
||
| 573 | * |
||
| 574 | * @return array The array with the EAV attributes matching the passed flag |
||
| 575 | */ |
||
| 576 | public function getEavAttributesByIsUserDefined($isUserDefined = 1) |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Return's an array with the available EAV attributes for the passed is entity type and |
||
| 583 | * user defined flag. |
||
| 584 | * |
||
| 585 | * @param integer $entityTypeId The entity type ID of the EAV attributes to return |
||
| 586 | * @param integer $isUserDefined The flag itself |
||
| 587 | * |
||
| 588 | * @return array The array with the EAV attributes matching the passed entity type and user defined flag |
||
| 589 | */ |
||
| 590 | public function getEavAttributesByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined = 1) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Return's an array with all available EAV entity types with the entity type code as key. |
||
| 597 | * |
||
| 598 | * @return array The available link types |
||
| 599 | */ |
||
| 600 | public function getEavEntityTypes() |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Return's an array with the available stores. |
||
| 607 | * |
||
| 608 | * @return array The array with the available stores |
||
| 609 | */ |
||
| 610 | public function getStores() |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Return's the default store. |
||
| 617 | * |
||
| 618 | * @return array The default store |
||
| 619 | */ |
||
| 620 | public function getDefaultStore() |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Return's an array with the available store websites. |
||
| 627 | * |
||
| 628 | * @return array The array with the available store websites |
||
| 629 | */ |
||
| 630 | public function getStoreWebsites() |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Return's an array with the available tax classes. |
||
| 637 | * |
||
| 638 | * @return array The array with the available tax classes |
||
| 639 | */ |
||
| 640 | public function getTaxClasses() |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Return's an array with all available categories. |
||
| 647 | * |
||
| 648 | * @return array The available categories |
||
| 649 | */ |
||
| 650 | public function getCategories() |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Return's an array with the root categories with the store code as key. |
||
| 657 | * |
||
| 658 | * @return array The root categories |
||
| 659 | */ |
||
| 660 | public function getRootCategories() |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Returns the category varchar values for the categories with |
||
| 667 | * the passed with the passed entity IDs. |
||
| 668 | * |
||
| 669 | * @param array $entityIds The array with the category IDs |
||
| 670 | * |
||
| 671 | * @return mixed The category varchar values |
||
| 672 | */ |
||
| 673 | public function getCategoryVarcharsByEntityIds(array $entityIds) |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Return's an array with all available link types. |
||
| 680 | * |
||
| 681 | * @return array The available link types |
||
| 682 | */ |
||
| 683 | public function getLinkTypes() |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Return's an array with all available link attributes. |
||
| 690 | * |
||
| 691 | * @return array The available link attributes |
||
| 692 | */ |
||
| 693 | public function getLinkAttributes() |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Return's an array with the Magento 2 configuration. |
||
| 700 | * |
||
| 701 | * @return array The Magento 2 configuration |
||
| 702 | */ |
||
| 703 | public function getCoreConfigData() |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Returns the array with the global data necessary for the |
||
| 710 | * import process. |
||
| 711 | * |
||
| 712 | * @return array The array with the global data |
||
| 713 | */ |
||
| 714 | public function getGlobalData() |
||
| 772 | } |
||
| 773 |
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..