Complex classes like Configuration 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 Configuration, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 39 | class Configuration implements ConfigurationInterface |
||
| 40 | { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The default PID filename to use. |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | const PID_FILENAME = 'importer.pid'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Mapping for boolean values passed on the console. |
||
| 51 | * |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | protected $booleanMapping = array( |
||
| 55 | 'true' => true, |
||
| 56 | 'false' => false, |
||
| 57 | '1' => true, |
||
| 58 | '0' => false, |
||
| 59 | 'on' => true, |
||
| 60 | 'off' => false |
||
| 61 | ); |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The operation name to use. |
||
| 65 | * |
||
| 66 | * @var string |
||
| 67 | * @Type("string") |
||
| 68 | * @SerializedName("operation-name") |
||
| 69 | */ |
||
| 70 | protected $operationName; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The Magento edition, EE or CE. |
||
| 74 | * |
||
| 75 | * @var string |
||
| 76 | * @Type("string") |
||
| 77 | * @SerializedName("magento-edition") |
||
| 78 | */ |
||
| 79 | protected $magentoEdition = 'CE'; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The Magento version, e. g. 2.1.0. |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | * @Type("string") |
||
| 86 | * @SerializedName("magento-version") |
||
| 87 | */ |
||
| 88 | protected $magentoVersion = '2.1.2'; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * The Magento installation directory. |
||
| 92 | * |
||
| 93 | * @var string |
||
| 94 | * @Type("string") |
||
| 95 | * @SerializedName("installation-dir") |
||
| 96 | */ |
||
| 97 | protected $installationDir; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The source directory that has to be watched for new files. |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | * @Type("string") |
||
| 104 | * @SerializedName("source-dir") |
||
| 105 | */ |
||
| 106 | protected $sourceDir; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The target directory with the files that has been imported. |
||
| 110 | * |
||
| 111 | * @var string |
||
| 112 | * @Type("string") |
||
| 113 | * @SerializedName("target-dir") |
||
| 114 | */ |
||
| 115 | protected $targetDir; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * ArrayCollection with the information of the configured databases. |
||
| 119 | * |
||
| 120 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
| 121 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Database>") |
||
| 122 | */ |
||
| 123 | protected $databases; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * ArrayCollection with the information of the configured loggers. |
||
| 127 | * |
||
| 128 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
| 129 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Logger>") |
||
| 130 | */ |
||
| 131 | protected $loggers; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * ArrayCollection with the information of the configured operations. |
||
| 135 | * |
||
| 136 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
| 137 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Operation>") |
||
| 138 | */ |
||
| 139 | protected $operations; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The subject's utility class with the SQL statements to use. |
||
| 143 | * |
||
| 144 | * @var string |
||
| 145 | * @Type("string") |
||
| 146 | * @SerializedName("utility-class-name") |
||
| 147 | */ |
||
| 148 | protected $utilityClassName; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * The source date format to use in the subject. |
||
| 152 | * |
||
| 153 | * @var string |
||
| 154 | * @Type("string") |
||
| 155 | * @SerializedName("source-date-format") |
||
| 156 | */ |
||
| 157 | protected $sourceDateFormat = 'n/d/y, g:i A'; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * The subject's multiple field delimiter character for fields with multiple values, defaults to (,). |
||
| 161 | * |
||
| 162 | * @var string |
||
| 163 | * @Type("string") |
||
| 164 | * @SerializedName("multiple-field-delimiter") |
||
| 165 | */ |
||
| 166 | protected $multipleFieldDelimiter = ','; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * The subject's delimiter character for CSV files. |
||
| 170 | * |
||
| 171 | * @var string |
||
| 172 | * @Type("string") |
||
| 173 | */ |
||
| 174 | protected $delimiter; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * The subject's enclosure character for CSV files. |
||
| 178 | * |
||
| 179 | * @var string |
||
| 180 | * @Type("string") |
||
| 181 | */ |
||
| 182 | protected $enclosure; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * The subject's escape character for CSV files. |
||
| 186 | * |
||
| 187 | * @var string |
||
| 188 | * @Type("string") |
||
| 189 | */ |
||
| 190 | protected $escape; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * The subject's source charset for the CSV file. |
||
| 194 | * |
||
| 195 | * @var string |
||
| 196 | * @Type("string") |
||
| 197 | * @SerializedName("from-charset") |
||
| 198 | */ |
||
| 199 | protected $fromCharset; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * The subject's target charset for a CSV file. |
||
| 203 | * |
||
| 204 | * @var string |
||
| 205 | * @Type("string") |
||
| 206 | * @SerializedName("to-charset") |
||
| 207 | */ |
||
| 208 | protected $toCharset; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * The subject's file mode for a CSV target file. |
||
| 212 | * |
||
| 213 | * @var string |
||
| 214 | * @Type("string") |
||
| 215 | * @SerializedName("file-mode") |
||
| 216 | */ |
||
| 217 | protected $fileMode; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * The flag to signal that the subject has to use the strict mode or not. |
||
| 221 | * |
||
| 222 | * @var boolean |
||
| 223 | * @Type("boolean") |
||
| 224 | * @SerializedName("strict-mode") |
||
| 225 | */ |
||
| 226 | protected $strictMode; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * The flag whether or not the import artefacts have to be archived. |
||
| 230 | * |
||
| 231 | * @var boolean |
||
| 232 | * @Type("boolean") |
||
| 233 | * @SerializedName("archive-artefacts") |
||
| 234 | */ |
||
| 235 | protected $archiveArtefacts; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * The directory where the archives will be stored. |
||
| 239 | * |
||
| 240 | * @var string |
||
| 241 | * @Type("string") |
||
| 242 | * @SerializedName("archive-dir") |
||
| 243 | */ |
||
| 244 | protected $archiveDir; |
||
| 245 | |||
| 246 | /** |
||
| 247 | * The flag to signal that the subject has to use the debug mode or not. |
||
| 248 | * |
||
| 249 | * @var boolean |
||
| 250 | * @Type("boolean") |
||
| 251 | * @SerializedName("debug-mode") |
||
| 252 | */ |
||
| 253 | protected $debugMode = false; |
||
| 254 | |||
| 255 | /** |
||
| 256 | * The flag to signal that the an existing PID should be ignored, whether or import process is running or not. |
||
| 257 | * |
||
| 258 | * @var boolean |
||
| 259 | * @Type("boolean") |
||
| 260 | * @SerializedName("ignore-pid") |
||
| 261 | */ |
||
| 262 | protected $ignorePid = false; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * The log level to use (see Monolog documentation). |
||
| 266 | * |
||
| 267 | * @var string |
||
| 268 | * @Type("string") |
||
| 269 | * @SerializedName("log-level") |
||
| 270 | */ |
||
| 271 | protected $logLevel = LogLevel::INFO; |
||
| 272 | |||
| 273 | /** |
||
| 274 | * The explicit DB ID to use. |
||
| 275 | * |
||
| 276 | * @var string |
||
| 277 | * @Type("string") |
||
| 278 | * @SerializedName("use-db-id") |
||
| 279 | */ |
||
| 280 | protected $useDbId; |
||
| 281 | |||
| 282 | /** |
||
| 283 | * The explicit PID filename to use. |
||
| 284 | * |
||
| 285 | * @var string |
||
| 286 | * @Type("string") |
||
| 287 | * @SerializedName("pid-filename") |
||
| 288 | */ |
||
| 289 | protected $pidFilename; |
||
| 290 | |||
| 291 | /** |
||
| 292 | * The entity type code to use. |
||
| 293 | * |
||
| 294 | * @var string |
||
| 295 | * @Type("string") |
||
| 296 | * @SerializedName("entity-type-code") |
||
| 297 | */ |
||
| 298 | protected $entityTypeCode; |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Return's the array with the plugins of the operation to use. |
||
| 302 | * |
||
| 303 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the plugins |
||
| 304 | * @throws \Exception Is thrown, if no plugins are available for the actual operation |
||
| 305 | */ |
||
| 306 | public function getPlugins() |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Map's the passed value to a boolean. |
||
| 323 | * |
||
| 324 | * @param string $value The value to map |
||
| 325 | * |
||
| 326 | * @return boolean The mapped value |
||
| 327 | * @throws \Exception Is thrown, if the value can't be mapped |
||
| 328 | */ |
||
| 329 | public function mapBoolean($value) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Return's the operation, initialize from the actual operation name. |
||
| 343 | * |
||
| 344 | * @return \TechDivision\Import\Configuration\OperationInterface The operation instance |
||
| 345 | */ |
||
| 346 | protected function getOperation() |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Return's the operation name that has to be used. |
||
| 353 | * |
||
| 354 | * @param string $operationName The operation name that has to be used |
||
| 355 | * |
||
| 356 | * @return void |
||
| 357 | */ |
||
| 358 | public function setOperationName($operationName) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Return's the operation name that has to be used. |
||
| 365 | * |
||
| 366 | * @return string The operation name that has to be used |
||
| 367 | */ |
||
| 368 | public function getOperationName() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Set's the Magento installation directory. |
||
| 375 | * |
||
| 376 | * @param string $installationDir The Magento installation directory |
||
| 377 | * |
||
| 378 | * @return void |
||
| 379 | */ |
||
| 380 | public function setInstallationDir($installationDir) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Return's the Magento installation directory. |
||
| 387 | * |
||
| 388 | * @return string The Magento installation directory |
||
| 389 | */ |
||
| 390 | public function getInstallationDir() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Set's the source directory that has to be watched for new files. |
||
| 397 | * |
||
| 398 | * @param string $sourceDir The source directory |
||
| 399 | * |
||
| 400 | * @return void |
||
| 401 | */ |
||
| 402 | public function setSourceDir($sourceDir) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Return's the source directory that has to be watched for new files. |
||
| 409 | * |
||
| 410 | * @return string The source directory |
||
| 411 | */ |
||
| 412 | public function getSourceDir() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Return's the target directory with the files that has been imported. |
||
| 419 | * |
||
| 420 | * @return string The target directory |
||
| 421 | */ |
||
| 422 | public function getTargetDir() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Set's the target directory with the files that has been imported. |
||
| 429 | * |
||
| 430 | * @param string $targetDir The target directory |
||
| 431 | * |
||
| 432 | * @return void |
||
| 433 | */ |
||
| 434 | public function setTargetDir($targetDir) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Return's the utility class with the SQL statements to use. |
||
| 441 | * |
||
| 442 | * @param string $utilityClassName The utility class name |
||
| 443 | * |
||
| 444 | * @return void |
||
| 445 | */ |
||
| 446 | public function setUtilityClassName($utilityClassName) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Return's the utility class with the SQL statements to use. |
||
| 453 | * |
||
| 454 | * @return string The utility class name |
||
| 455 | */ |
||
| 456 | public function getUtilityClassName() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Set's the Magento edition, EE or CE. |
||
| 463 | * |
||
| 464 | * @param string $magentoEdition The Magento edition |
||
| 465 | * |
||
| 466 | * @return void |
||
| 467 | */ |
||
| 468 | public function setMagentoEdition($magentoEdition) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Return's the Magento edition, EE or CE. |
||
| 475 | * |
||
| 476 | * @return string The Magento edition |
||
| 477 | */ |
||
| 478 | public function getMagentoEdition() |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Return's the Magento version, e. g. 2.1.0. |
||
| 485 | * |
||
| 486 | * @param string $magentoVersion The Magento version |
||
| 487 | * |
||
| 488 | * @return void |
||
| 489 | */ |
||
| 490 | public function setMagentoVersion($magentoVersion) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Return's the Magento version, e. g. 2.1.0. |
||
| 497 | * |
||
| 498 | * @return string The Magento version |
||
| 499 | */ |
||
| 500 | public function getMagentoVersion() |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Return's the subject's source date format to use. |
||
| 507 | * |
||
| 508 | * @return string The source date format |
||
| 509 | */ |
||
| 510 | public function getSourceDateFormat() |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Set's the subject's source date format to use. |
||
| 517 | * |
||
| 518 | * @param string $sourceDateFormat The source date format |
||
| 519 | * |
||
| 520 | * @return void |
||
| 521 | */ |
||
| 522 | public function setSourceDateFormat($sourceDateFormat) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
| 529 | * |
||
| 530 | * @return string The multiple field delimiter character |
||
| 531 | */ |
||
| 532 | public function getMultipleFieldDelimiter() |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Return's the delimiter character to use, default value is comma (,). |
||
| 539 | * |
||
| 540 | * @return string The delimiter character |
||
| 541 | */ |
||
| 542 | public function getDelimiter() |
||
| 546 | |||
| 547 | /** |
||
| 548 | * The enclosure character to use, default value is double quotation ("). |
||
| 549 | * |
||
| 550 | * @return string The enclosure character |
||
| 551 | */ |
||
| 552 | public function getEnclosure() |
||
| 556 | |||
| 557 | /** |
||
| 558 | * The escape character to use, default value is backslash (\). |
||
| 559 | * |
||
| 560 | * @return string The escape character |
||
| 561 | */ |
||
| 562 | public function getEscape() |
||
| 566 | |||
| 567 | /** |
||
| 568 | * The file encoding of the CSV source file, default value is UTF-8. |
||
| 569 | * |
||
| 570 | * @return string The charset used by the CSV source file |
||
| 571 | */ |
||
| 572 | public function getFromCharset() |
||
| 576 | |||
| 577 | /** |
||
| 578 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
| 579 | * |
||
| 580 | * @return string The charset used by the CSV target file |
||
| 581 | */ |
||
| 582 | public function getToCharset() |
||
| 586 | |||
| 587 | /** |
||
| 588 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
| 589 | * |
||
| 590 | * @return string The file mode of the CSV target file |
||
| 591 | */ |
||
| 592 | public function getFileMode() |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
| 599 | * |
||
| 600 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
| 601 | */ |
||
| 602 | public function isStrictMode() |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Return's the entity type code to be used. |
||
| 609 | * |
||
| 610 | * @return string The entity type code to be used |
||
| 611 | */ |
||
| 612 | public function getEntityTypeCode() |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Remove's all configured database configuration. |
||
| 619 | * |
||
| 620 | * @return void |
||
| 621 | */ |
||
| 622 | public function clearDatabases() |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Add's the passed database configuration. |
||
| 629 | * |
||
| 630 | * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration |
||
| 631 | * |
||
| 632 | * @return void |
||
| 633 | */ |
||
| 634 | public function addDatabase(DatabaseConfigurationInterface $database) |
||
| 638 | |||
| 639 | /** |
||
| 640 | * Return's the database configuration. |
||
| 641 | * |
||
| 642 | * If an explicit DB ID is specified, the method tries to return the database with this ID. If |
||
| 643 | * the database configuration is NOT available, an execption is thrown. |
||
| 644 | * |
||
| 645 | * If no explicit DB ID is specified, the method tries to return the default database configuration, |
||
| 646 | * if not available the first one. |
||
| 647 | * |
||
| 648 | * @return \TechDivision\Import\Cli\Configuration\Database The database configuration |
||
| 649 | * @throws \Exception Is thrown, if no database configuration is available |
||
| 650 | */ |
||
| 651 | public function getDatabase() |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Return's the ArrayCollection with the configured operations. |
||
| 687 | * |
||
| 688 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
| 689 | */ |
||
| 690 | public function getOperations() |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Return's the ArrayCollection with the configured loggers. |
||
| 697 | * |
||
| 698 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the loggers |
||
| 699 | */ |
||
| 700 | public function getLoggers() |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Return's the TRUE if the import artefacts have to be archived. |
||
| 707 | * |
||
| 708 | * @return boolean TRUE if the import artefacts have to be archived |
||
| 709 | */ |
||
| 710 | public function haveArchiveArtefacts() |
||
| 714 | |||
| 715 | /** |
||
| 716 | * The directory where the archives will be stored. |
||
| 717 | * |
||
| 718 | * @return string The archive directory |
||
| 719 | */ |
||
| 720 | public function getArchiveDir() |
||
| 724 | |||
| 725 | /** |
||
| 726 | * Set's the debug mode. |
||
| 727 | * |
||
| 728 | * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE |
||
| 729 | * |
||
| 730 | * @return void |
||
| 731 | */ |
||
| 732 | public function setDebugMode($debugMode) |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
| 739 | * |
||
| 740 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
| 741 | */ |
||
| 742 | public function isDebugMode() |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Set's the flag to signal that the an existing PID has to be ignored, whether a |
||
| 749 | * import process is running or not. |
||
| 750 | * |
||
| 751 | * @param boolean $ignorePid TRUE if the PID has to be ignored, else FALSE |
||
| 752 | * |
||
| 753 | * @return void |
||
| 754 | */ |
||
| 755 | public function setIgnorePid($ignorePid) |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Queries whether or not that the an existing PID has to be ignored. |
||
| 762 | * |
||
| 763 | * @return boolean TRUE if an existing PID has to be ignored, else FALSE |
||
| 764 | */ |
||
| 765 | public function isIgnorePid() |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Set's the log level to use. |
||
| 772 | * |
||
| 773 | * @param string $logLevel The log level to use |
||
| 774 | * |
||
| 775 | * @return void |
||
| 776 | */ |
||
| 777 | public function setLogLevel($logLevel) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Return's the log level to use. |
||
| 784 | * |
||
| 785 | * @return string The log level to use |
||
| 786 | */ |
||
| 787 | public function getLogLevel() |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Set's the explicit DB ID to use. |
||
| 794 | * |
||
| 795 | * @param string $useDbId The explicit DB ID to use |
||
| 796 | * |
||
| 797 | * @return void |
||
| 798 | */ |
||
| 799 | public function setUseDbId($useDbId) |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Return's the explicit DB ID to use. |
||
| 806 | * |
||
| 807 | * @return string The explicit DB ID to use |
||
| 808 | */ |
||
| 809 | public function getUseDbId() |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Set's the PID filename to use. |
||
| 816 | * |
||
| 817 | * @param string $pidFilename The PID filename to use |
||
| 818 | * |
||
| 819 | * @return void |
||
| 820 | */ |
||
| 821 | public function setPidFilename($pidFilename) |
||
| 825 | |||
| 826 | /** |
||
| 827 | * Return's the PID filename to use. |
||
| 828 | * |
||
| 829 | * @return string The PID filename to use |
||
| 830 | */ |
||
| 831 | public function getPidFilename() |
||
| 835 | } |
||
| 836 |