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 |
||
42 | class Configuration implements ConfigurationInterface |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * Mapping for boolean values passed on the console. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $booleanMapping = array( |
||
51 | 'true' => true, |
||
52 | 'false' => false, |
||
53 | '1' => true, |
||
54 | '0' => false, |
||
55 | 'on' => true, |
||
56 | 'off' => false |
||
57 | ); |
||
58 | |||
59 | /** |
||
60 | * The operation name to use. |
||
61 | * |
||
62 | * @var string |
||
63 | * @Type("string") |
||
64 | * @SerializedName("operation-name") |
||
65 | */ |
||
66 | protected $operationName; |
||
67 | |||
68 | /** |
||
69 | * The Magento edition, EE or CE. |
||
70 | * |
||
71 | * @var string |
||
72 | * @Type("string") |
||
73 | * @SerializedName("magento-edition") |
||
74 | */ |
||
75 | protected $magentoEdition = 'CE'; |
||
76 | |||
77 | /** |
||
78 | * The Magento version, e. g. 2.1.0. |
||
79 | * |
||
80 | * @var string |
||
81 | * @Type("string") |
||
82 | * @SerializedName("magento-version") |
||
83 | */ |
||
84 | protected $magentoVersion = '2.1.2'; |
||
85 | |||
86 | /** |
||
87 | * The Magento installation directory. |
||
88 | * |
||
89 | * @var string |
||
90 | * @Type("string") |
||
91 | * @SerializedName("installation-dir") |
||
92 | */ |
||
93 | protected $installationDir; |
||
94 | |||
95 | /** |
||
96 | * The source directory that has to be watched for new files. |
||
97 | * |
||
98 | * @var string |
||
99 | * @Type("string") |
||
100 | * @SerializedName("source-dir") |
||
101 | */ |
||
102 | protected $sourceDir; |
||
103 | |||
104 | /** |
||
105 | * The target directory with the files that has been imported. |
||
106 | * |
||
107 | * @var string |
||
108 | * @Type("string") |
||
109 | * @SerializedName("target-dir") |
||
110 | */ |
||
111 | protected $targetDir; |
||
112 | |||
113 | /** |
||
114 | * ArrayCollection with the information of the configured databases. |
||
115 | * |
||
116 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
117 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Database>") |
||
118 | */ |
||
119 | protected $databases; |
||
120 | |||
121 | /** |
||
122 | * ArrayCollection with the information of the configured operations. |
||
123 | * |
||
124 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
125 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Operation>") |
||
126 | */ |
||
127 | protected $operations; |
||
128 | |||
129 | /** |
||
130 | * The subject's utility class with the SQL statements to use. |
||
131 | * |
||
132 | * @var string |
||
133 | * @Type("string") |
||
134 | * @SerializedName("utility-class-name") |
||
135 | */ |
||
136 | protected $utilityClassName; |
||
137 | |||
138 | /** |
||
139 | * The source date format to use in the subject. |
||
140 | * |
||
141 | * @var string |
||
142 | * @Type("string") |
||
143 | * @SerializedName("source-date-format") |
||
144 | */ |
||
145 | protected $sourceDateFormat = 'n/d/y, g:i A'; |
||
146 | |||
147 | /** |
||
148 | * The subject's multiple field delimiter character for fields with multiple values, defaults to (,). |
||
149 | * |
||
150 | * @var string |
||
151 | * @Type("string") |
||
152 | * @SerializedName("multiple-field-delimiter") |
||
153 | */ |
||
154 | protected $multipleFieldDelimiter = ','; |
||
155 | |||
156 | /** |
||
157 | * The subject's delimiter character for CSV files. |
||
158 | * |
||
159 | * @var string |
||
160 | * @Type("string") |
||
161 | */ |
||
162 | protected $delimiter; |
||
163 | |||
164 | /** |
||
165 | * The subject's enclosure character for CSV files. |
||
166 | * |
||
167 | * @var string |
||
168 | * @Type("string") |
||
169 | */ |
||
170 | protected $enclosure; |
||
171 | |||
172 | /** |
||
173 | * The subject's escape character for CSV files. |
||
174 | * |
||
175 | * @var string |
||
176 | * @Type("string") |
||
177 | */ |
||
178 | protected $escape; |
||
179 | |||
180 | /** |
||
181 | * The subject's source charset for the CSV file. |
||
182 | * |
||
183 | * @var string |
||
184 | * @Type("string") |
||
185 | * @SerializedName("from-charset") |
||
186 | */ |
||
187 | protected $fromCharset; |
||
188 | |||
189 | /** |
||
190 | * The subject's target charset for a CSV file. |
||
191 | * |
||
192 | * @var string |
||
193 | * @Type("string") |
||
194 | * @SerializedName("to-charset") |
||
195 | */ |
||
196 | protected $toCharset; |
||
197 | |||
198 | /** |
||
199 | * The subject's file mode for a CSV target file. |
||
200 | * |
||
201 | * @var string |
||
202 | * @Type("string") |
||
203 | * @SerializedName("file-mode") |
||
204 | */ |
||
205 | protected $fileMode; |
||
206 | |||
207 | /** |
||
208 | * The flag to signal that the subject has to use the strict mode or not. |
||
209 | * |
||
210 | * @var boolean |
||
211 | * @Type("boolean") |
||
212 | * @SerializedName("strict-mode") |
||
213 | */ |
||
214 | protected $strictMode; |
||
215 | |||
216 | /** |
||
217 | * The flag whether or not the import artefacts have to be archived. |
||
218 | * |
||
219 | * @var boolean |
||
220 | * @Type("boolean") |
||
221 | * @SerializedName("archive-artefacts") |
||
222 | */ |
||
223 | protected $archiveArtefacts; |
||
224 | |||
225 | /** |
||
226 | * The directory where the archives will be stored. |
||
227 | * |
||
228 | * @var string |
||
229 | * @Type("string") |
||
230 | * @SerializedName("archive-dir") |
||
231 | */ |
||
232 | protected $archiveDir; |
||
233 | |||
234 | /** |
||
235 | * The flag to signal that the subject has to use the debug mode or not. |
||
236 | * |
||
237 | * @var boolean |
||
238 | * @Type("boolean") |
||
239 | * @SerializedName("debug-mode") |
||
240 | */ |
||
241 | protected $debugMode = false; |
||
242 | |||
243 | /** |
||
244 | * The flag to signal that the an existing PID should be ignored, whether or import process is running or not. |
||
245 | * |
||
246 | * @var boolean |
||
247 | * @Type("boolean") |
||
248 | * @SerializedName("ignore-pid") |
||
249 | */ |
||
250 | protected $ignorePid = false; |
||
251 | |||
252 | /** |
||
253 | * The log level to use (see Monolog documentation). |
||
254 | * |
||
255 | * @var string |
||
256 | * @Type("string") |
||
257 | * @SerializedName("log-level") |
||
258 | */ |
||
259 | protected $logLevel = LogLevel::INFO; |
||
260 | |||
261 | /** |
||
262 | * Factory implementation to create a new initialized configuration instance. |
||
263 | * |
||
264 | * If command line options are specified, they will always override the |
||
265 | * values found in the configuration file. |
||
266 | * |
||
267 | * @param \Symfony\Component\Console\Input\InputInterface $input The Symfony console input instance |
||
268 | * |
||
269 | * @return \TechDivision\Import\Cli\Configuration The configuration instance |
||
270 | * @throws \Exception Is thrown, if the specified configuration file doesn't exist |
||
271 | */ |
||
272 | public static function factory(InputInterface $input) |
||
383 | |||
384 | /** |
||
385 | * Return's the array with the subjects of the operation to use. |
||
386 | * |
||
387 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the subjects |
||
388 | * @throws \Exception Is thrown, if no subjects are available for the actual operation |
||
389 | */ |
||
390 | public function getSubjects() |
||
404 | |||
405 | /** |
||
406 | * Map's the passed value to a boolean. |
||
407 | * |
||
408 | * @param string $value The value to map |
||
409 | * |
||
410 | * @return boolean The mapped value |
||
411 | * @throws \Exception Is thrown, if the value can't be mapped |
||
412 | */ |
||
413 | public function mapBoolean($value) |
||
424 | |||
425 | /** |
||
426 | * Return's the operation, initialize from the actual operation name. |
||
427 | * |
||
428 | * @return \TechDivision\Import\Configuration\OperationInterface The operation instance |
||
429 | */ |
||
430 | protected function getOperation() |
||
434 | |||
435 | /** |
||
436 | * Return's the operation name that has to be used. |
||
437 | * |
||
438 | * @param string $operationName The operation name that has to be used |
||
439 | * |
||
440 | * @return void |
||
441 | */ |
||
442 | public function setOperationName($operationName) |
||
446 | |||
447 | /** |
||
448 | * Return's the operation name that has to be used. |
||
449 | * |
||
450 | * @return string The operation name that has to be used |
||
451 | */ |
||
452 | public function getOperationName() |
||
456 | |||
457 | /** |
||
458 | * Set's the Magento installation directory. |
||
459 | * |
||
460 | * @param string $installationDir The Magento installation directory |
||
461 | * |
||
462 | * @return void |
||
463 | */ |
||
464 | public function setInstallationDir($installationDir) |
||
468 | |||
469 | /** |
||
470 | * Return's the Magento installation directory. |
||
471 | * |
||
472 | * @return string The Magento installation directory |
||
473 | */ |
||
474 | public function getInstallationDir() |
||
478 | |||
479 | /** |
||
480 | * Set's the source directory that has to be watched for new files. |
||
481 | * |
||
482 | * @param string $sourceDir The source directory |
||
483 | * |
||
484 | * @return void |
||
485 | */ |
||
486 | public function setSourceDir($sourceDir) |
||
490 | |||
491 | /** |
||
492 | * Return's the source directory that has to be watched for new files. |
||
493 | * |
||
494 | * @return string The source directory |
||
495 | */ |
||
496 | public function getSourceDir() |
||
500 | |||
501 | /** |
||
502 | * Return's the target directory with the files that has been imported. |
||
503 | * |
||
504 | * @return string The target directory |
||
505 | */ |
||
506 | public function getTargetDir() |
||
510 | |||
511 | /** |
||
512 | * Set's the target directory with the files that has been imported. |
||
513 | * |
||
514 | * @param string $targetDir The target directory |
||
515 | * |
||
516 | * @return void |
||
517 | */ |
||
518 | public function setTargetDir($targetDir) |
||
522 | |||
523 | /** |
||
524 | * Return's the utility class with the SQL statements to use. |
||
525 | * |
||
526 | * @param string $utilityClassName The utility class name |
||
527 | * |
||
528 | * @return void |
||
529 | */ |
||
530 | public function setUtilityClassName($utilityClassName) |
||
534 | |||
535 | /** |
||
536 | * Return's the utility class with the SQL statements to use. |
||
537 | * |
||
538 | * @return string The utility class name |
||
539 | */ |
||
540 | public function getUtilityClassName() |
||
544 | |||
545 | /** |
||
546 | * Set's the Magento edition, EE or CE. |
||
547 | * |
||
548 | * @param string $magentoEdition The Magento edition |
||
549 | * |
||
550 | * @return void |
||
551 | */ |
||
552 | public function setMagentoEdition($magentoEdition) |
||
556 | |||
557 | /** |
||
558 | * Return's the Magento edition, EE or CE. |
||
559 | * |
||
560 | * @return string The Magento edition |
||
561 | */ |
||
562 | public function getMagentoEdition() |
||
566 | |||
567 | /** |
||
568 | * Return's the Magento version, e. g. 2.1.0. |
||
569 | * |
||
570 | * @param string $magentoVersion The Magento version |
||
571 | * |
||
572 | * @return void |
||
573 | */ |
||
574 | public function setMagentoVersion($magentoVersion) |
||
578 | |||
579 | /** |
||
580 | * Return's the Magento version, e. g. 2.1.0. |
||
581 | * |
||
582 | * @return string The Magento version |
||
583 | */ |
||
584 | public function getMagentoVersion() |
||
588 | |||
589 | /** |
||
590 | * Return's the subject's source date format to use. |
||
591 | * |
||
592 | * @return string The source date format |
||
593 | */ |
||
594 | public function getSourceDateFormat() |
||
598 | |||
599 | /** |
||
600 | * Set's the subject's source date format to use. |
||
601 | * |
||
602 | * @param string $sourceDateFormat The source date format |
||
603 | * |
||
604 | * @return void |
||
605 | */ |
||
606 | public function setSourceDateFormat($sourceDateFormat) |
||
610 | |||
611 | /** |
||
612 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
613 | * |
||
614 | * @return string The multiple field delimiter character |
||
615 | */ |
||
616 | public function getMultipleFieldDelimiter() |
||
620 | |||
621 | /** |
||
622 | * Return's the delimiter character to use, default value is comma (,). |
||
623 | * |
||
624 | * @return string The delimiter character |
||
625 | */ |
||
626 | public function getDelimiter() |
||
630 | |||
631 | /** |
||
632 | * The enclosure character to use, default value is double quotation ("). |
||
633 | * |
||
634 | * @return string The enclosure character |
||
635 | */ |
||
636 | public function getEnclosure() |
||
640 | |||
641 | /** |
||
642 | * The escape character to use, default value is backslash (\). |
||
643 | * |
||
644 | * @return string The escape character |
||
645 | */ |
||
646 | public function getEscape() |
||
650 | |||
651 | /** |
||
652 | * The file encoding of the CSV source file, default value is UTF-8. |
||
653 | * |
||
654 | * @return string The charset used by the CSV source file |
||
655 | */ |
||
656 | public function getFromCharset() |
||
660 | |||
661 | /** |
||
662 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
663 | * |
||
664 | * @return string The charset used by the CSV target file |
||
665 | */ |
||
666 | public function getToCharset() |
||
670 | |||
671 | /** |
||
672 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
673 | * |
||
674 | * @return string The file mode of the CSV target file |
||
675 | */ |
||
676 | public function getFileMode() |
||
680 | |||
681 | /** |
||
682 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
683 | * |
||
684 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
685 | */ |
||
686 | public function isStrictMode() |
||
690 | |||
691 | /** |
||
692 | * Return's the database configuration. |
||
693 | * |
||
694 | * @param string $id The ID of the database connection to return |
||
695 | * |
||
696 | * @return \TechDivision\Import\Cli\Configuration\Database The database configuration |
||
697 | * @throws \Exception Is thrown, if the database with the passed ID is not configured |
||
698 | */ |
||
699 | public function getDatabase($id = null) |
||
724 | |||
725 | /** |
||
726 | * Return's the ArrayCollection with the configured operations. |
||
727 | * |
||
728 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
729 | */ |
||
730 | public function getOperations() |
||
734 | |||
735 | /** |
||
736 | * Return's the TRUE if the import artefacts have to be archived. |
||
737 | * |
||
738 | * @return boolean TRUE if the import artefacts have to be archived |
||
739 | */ |
||
740 | public function haveArchiveArtefacts() |
||
744 | |||
745 | /** |
||
746 | * The directory where the archives will be stored. |
||
747 | * |
||
748 | * @return string The archive directory |
||
749 | */ |
||
750 | public function getArchiveDir() |
||
754 | |||
755 | /** |
||
756 | * Set's the debug mode. |
||
757 | * |
||
758 | * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE |
||
759 | * |
||
760 | * @return void |
||
761 | */ |
||
762 | public function setDebugMode($debugMode) |
||
766 | |||
767 | /** |
||
768 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
769 | * |
||
770 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
771 | */ |
||
772 | public function isDebugMode() |
||
776 | |||
777 | /** |
||
778 | * Set's the flag to signal that the an existing PID hast to be ignored, whether a |
||
779 | * import process is running or not. |
||
780 | * |
||
781 | * @param boolean $ignorePid TRUE if the PID has to be ignored, else FALSE |
||
782 | * |
||
783 | * @return void |
||
784 | */ |
||
785 | public function setIgnorePid($ignorePid) |
||
789 | |||
790 | /** |
||
791 | * Queries whether or not that the an existing PID has to be ignored. |
||
792 | * |
||
793 | * @return boolean TRUE if an existing PID has to be ignored, else FALSE |
||
794 | */ |
||
795 | public function isIgnorePid() |
||
799 | |||
800 | /** |
||
801 | * Set's the log level to use. |
||
802 | * |
||
803 | * @param string $logLevel The log level to use |
||
804 | * |
||
805 | * @return void |
||
806 | */ |
||
807 | public function setLogLevel($logLevel) |
||
811 | |||
812 | /** |
||
813 | * Return's the log level to use. |
||
814 | * |
||
815 | * @return string The log level to use |
||
816 | */ |
||
817 | public function getLogLevel() |
||
821 | } |
||
822 |