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 |
||
| 32 | class ImportProcessor implements ImportProcessorInterface |
||
| 33 | { |
||
| 34 | |||
| 35 | /** |
||
| 36 | * A PDO connection initialized with the values from the Doctrine EntityManager. |
||
| 37 | * |
||
| 38 | * @var \PDO |
||
| 39 | */ |
||
| 40 | protected $connection; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The repository to access categories. |
||
| 44 | * |
||
| 45 | * @var \TechDivision\Import\Repositories\CategoryRepository |
||
| 46 | */ |
||
| 47 | protected $categoryRepository; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The repository to access category varchar values. |
||
| 51 | * |
||
| 52 | * @var \TechDivision\Import\Repositories\CategoryVarcharRepository |
||
| 53 | */ |
||
| 54 | protected $categoryVarcharRepository; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The repository to access EAV attributes. |
||
| 58 | * |
||
| 59 | * @var \TechDivision\Import\Repositories\EavAttributeRepository |
||
| 60 | */ |
||
| 61 | protected $eavAttributeRepository; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The repository to access EAV attribute set. |
||
| 65 | * |
||
| 66 | * @var \TechDivision\Import\Repositories\EavAttributeSetRepository |
||
| 67 | */ |
||
| 68 | protected $eavAttributeSetRepository; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The repository to access stores. |
||
| 72 | * |
||
| 73 | * @var \TechDivision\Import\Repositories\StoreRepository |
||
| 74 | */ |
||
| 75 | protected $storeRepository; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The repository to access store websites. |
||
| 79 | * |
||
| 80 | * @var \TechDivision\Import\Repositories\StoreWebsiteRepository |
||
| 81 | */ |
||
| 82 | protected $storeWebsiteRepository; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The repository to access tax classes. |
||
| 86 | * |
||
| 87 | * @var \TechDivision\Import\Repositories\TaxClassRepository |
||
| 88 | */ |
||
| 89 | protected $taxClassRepository; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * The repository to access link types. |
||
| 93 | * |
||
| 94 | * @var \TechDivision\Import\Repositories\LinkTypeRepository |
||
| 95 | */ |
||
| 96 | protected $linkTypeRepository; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * The repository to access link attributes. |
||
| 100 | * |
||
| 101 | * @var \TechDivision\Import\Repositories\LinkAttributeRepository |
||
| 102 | */ |
||
| 103 | protected $linkAttributeRepository; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The repository to access the configuration. |
||
| 107 | * |
||
| 108 | * @var \TechDivision\Import\Repositories\CoreConfigDataRepository |
||
| 109 | */ |
||
| 110 | protected $coreConfigDataRepository; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Set's the passed connection. |
||
| 114 | * |
||
| 115 | * @param \PDO $connection The connection to set |
||
| 116 | * |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | public function setConnection(\PDO $connection) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Return's the connection. |
||
| 126 | * |
||
| 127 | * @return \PDO The connection instance |
||
| 128 | */ |
||
| 129 | public function getConnection() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
| 136 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
| 137 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
| 138 | * to autocommit mode. |
||
| 139 | * |
||
| 140 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 141 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
| 142 | */ |
||
| 143 | public function beginTransaction() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
| 150 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
| 151 | * |
||
| 152 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 153 | * @link http://php.net/manual/en/pdo.commit.php |
||
| 154 | */ |
||
| 155 | public function commit() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
| 162 | * |
||
| 163 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
| 164 | * rolled back the transaction. |
||
| 165 | * |
||
| 166 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
| 167 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
| 168 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
| 169 | * |
||
| 170 | * @return boolean Returns TRUE on success or FALSE on failure |
||
| 171 | * @link http://php.net/manual/en/pdo.rollback.php |
||
| 172 | */ |
||
| 173 | public function rollBack() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Set's the repository to access categories. |
||
| 180 | * |
||
| 181 | * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories |
||
| 182 | * |
||
| 183 | * @return void |
||
| 184 | */ |
||
| 185 | public function setCategoryRepository($categoryRepository) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Return's the repository to access categories. |
||
| 192 | * |
||
| 193 | * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance |
||
| 194 | */ |
||
| 195 | public function getCategoryRepository() |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Return's the repository to access category varchar values. |
||
| 202 | * |
||
| 203 | * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance |
||
| 204 | * |
||
| 205 | * @return void |
||
| 206 | */ |
||
| 207 | public function setCategoryVarcharRepository($categoryVarcharRepository) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Return's the repository to access category varchar values. |
||
| 214 | * |
||
| 215 | * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance |
||
| 216 | */ |
||
| 217 | public function getCategoryVarcharRepository() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Set's the repository to access EAV attributes. |
||
| 224 | * |
||
| 225 | * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes |
||
| 226 | * |
||
| 227 | * @return void |
||
| 228 | */ |
||
| 229 | public function setEavAttributeRepository($eavAttributeRepository) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Return's the repository to access EAV attributes. |
||
| 236 | * |
||
| 237 | * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance |
||
| 238 | */ |
||
| 239 | public function getEavAttributeRepository() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Set's the repository to access EAV attribute sets. |
||
| 246 | * |
||
| 247 | * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets |
||
| 248 | * |
||
| 249 | * @return void |
||
| 250 | */ |
||
| 251 | public function setEavAttributeSetRepository($eavAttributeSetRepository) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Return's the repository to access EAV attribute sets. |
||
| 258 | * |
||
| 259 | * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance |
||
| 260 | */ |
||
| 261 | public function getEavAttributeSetRepository() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Set's the repository to access stores. |
||
| 268 | * |
||
| 269 | * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores |
||
| 270 | * |
||
| 271 | * @return void |
||
| 272 | */ |
||
| 273 | public function setStoreRepository($storeRepository) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Return's the repository to access stores. |
||
| 280 | * |
||
| 281 | * @return \TechDivision\Import\Repositories\StoreRepository The repository instance |
||
| 282 | */ |
||
| 283 | public function getStoreRepository() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Set's the repository to access store websites. |
||
| 290 | * |
||
| 291 | * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites |
||
| 292 | * |
||
| 293 | * @return void |
||
| 294 | */ |
||
| 295 | public function setStoreWebsiteRepository($storeWebsiteRepository) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Return's the repository to access store websites. |
||
| 302 | * |
||
| 303 | * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance |
||
| 304 | */ |
||
| 305 | public function getStoreWebsiteRepository() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Set's the repository to access tax classes. |
||
| 312 | * |
||
| 313 | * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores |
||
| 314 | * |
||
| 315 | * @return void |
||
| 316 | */ |
||
| 317 | public function setTaxClassRepository($taxClassRepository) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Return's the repository to access tax classes. |
||
| 324 | * |
||
| 325 | * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance |
||
| 326 | */ |
||
| 327 | public function getTaxClassRepository() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Set's the repository to access link types. |
||
| 334 | * |
||
| 335 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types |
||
| 336 | * |
||
| 337 | * @return void |
||
| 338 | */ |
||
| 339 | public function setLinkTypeRepository($linkTypeRepository) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Return's the repository to access link types. |
||
| 346 | * |
||
| 347 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 348 | */ |
||
| 349 | public function getLinkTypeRepository() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Set's the repository to access link attributes. |
||
| 356 | * |
||
| 357 | * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes |
||
| 358 | * |
||
| 359 | * @return void |
||
| 360 | */ |
||
| 361 | public function setLinkAttributeRepository($linkAttributeRepository) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Return's the repository to access link attributes. |
||
| 368 | * |
||
| 369 | * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance |
||
| 370 | */ |
||
| 371 | public function getLinkAttributeRepository() |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Set's the repository to access the Magento 2 configuration. |
||
| 378 | * |
||
| 379 | * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration |
||
| 380 | * |
||
| 381 | * @return void |
||
| 382 | */ |
||
| 383 | public function setCoreConfigDataRepository($coreConfigDataRepository) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Return's the repository to access the Magento 2 configuration. |
||
| 390 | * |
||
| 391 | * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance |
||
| 392 | */ |
||
| 393 | public function getCoreConfigDataRepository() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Return's the EAV attribute set with the passed ID. |
||
| 400 | * |
||
| 401 | * @param integer $id The ID of the EAV attribute set to load |
||
| 402 | * |
||
| 403 | * @return array The EAV attribute set |
||
| 404 | */ |
||
| 405 | public function getEavAttributeSet($id) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Return's the attribute sets for the passed entity type ID. |
||
| 412 | * |
||
| 413 | * @param mixed $entityTypeId The entity type ID to return the attribute sets for |
||
| 414 | * |
||
| 415 | * @return array|boolean The attribute sets for the passed entity type ID |
||
| 416 | */ |
||
| 417 | public function getEavAttributeSetsByEntityTypeId($entityTypeId) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Return's an array with the EAV attributes for the passed entity type ID and attribute set name. |
||
| 424 | * |
||
| 425 | * @param integer $entityTypeId The entity type ID of the EAV attributes to return |
||
| 426 | * @param string $attributeSetName The attribute set name of the EAV attributes to return |
||
| 427 | * |
||
| 428 | * @return array The |
||
| 429 | */ |
||
| 430 | public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Return's an array with the available EAV attributes for the passed option value and store ID. |
||
| 437 | * |
||
| 438 | * @param string $optionValue The option value of the EAV attributes |
||
| 439 | * @param string $storeId The store ID of the EAV attribues |
||
| 440 | * |
||
| 441 | * @return array The array with all available EAV attributes |
||
| 442 | */ |
||
| 443 | public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId) |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Return's the first EAV attribute for the passed option value and store ID. |
||
| 450 | * |
||
| 451 | * @param string $optionValue The option value of the EAV attributes |
||
| 452 | * @param string $storeId The store ID of the EAV attribues |
||
| 453 | * |
||
| 454 | * @return array The array with the EAV attribute |
||
| 455 | */ |
||
| 456 | public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Return's an array with the available EAV attributes for the passed is user defined flag. |
||
| 463 | * |
||
| 464 | * @param integer $isUserDefined The flag itself |
||
| 465 | * |
||
| 466 | * @return array The array with the EAV attributes matching the passed flag |
||
| 467 | */ |
||
| 468 | public function getEavAttributeByIsUserDefined($isUserDefined = 1) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Return's an array with the available stores. |
||
| 475 | * |
||
| 476 | * @return array The array with the available stores |
||
| 477 | */ |
||
| 478 | public function getStores() |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Return's the default store. |
||
| 485 | * |
||
| 486 | * @return array The default store |
||
| 487 | */ |
||
| 488 | public function getDefaultStore() |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Return's an array with the available store websites. |
||
| 495 | * |
||
| 496 | * @return array The array with the available store websites |
||
| 497 | */ |
||
| 498 | public function getStoreWebsites() |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Return's an array with the available tax classes. |
||
| 505 | * |
||
| 506 | * @return array The array with the available tax classes |
||
| 507 | */ |
||
| 508 | public function getTaxClasses() |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Return's an array with all available categories. |
||
| 515 | * |
||
| 516 | * @return array The available categories |
||
| 517 | */ |
||
| 518 | public function getCategories() |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Return's an array with the root categories with the store code as key. |
||
| 525 | * |
||
| 526 | * @return array The root categories |
||
| 527 | */ |
||
| 528 | public function getRootCategories() |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Returns the category varchar values for the categories with |
||
| 535 | * the passed with the passed entity IDs. |
||
| 536 | * |
||
| 537 | * @param array $entityIds The array with the category IDs |
||
| 538 | * |
||
| 539 | * @return mixed The category varchar values |
||
| 540 | */ |
||
| 541 | public function getCategoryVarcharsByEntityIds(array $entityIds) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Return's an array with all available link types. |
||
| 548 | * |
||
| 549 | * @return array The available link types |
||
| 550 | */ |
||
| 551 | public function getLinkTypes() |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Return's an array with all available link attributes. |
||
| 558 | * |
||
| 559 | * @return array The available link attributes |
||
| 560 | */ |
||
| 561 | public function getLinkAttributes() |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Return's an array with the Magento 2 configuration. |
||
| 568 | * |
||
| 569 | * @return array The Magento 2 configuration |
||
| 570 | */ |
||
| 571 | public function getCoreConfigData() |
||
| 575 | } |
||
| 576 |
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..