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 operations. |
||
127 | * |
||
128 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
129 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Operation>") |
||
130 | */ |
||
131 | protected $operations; |
||
132 | |||
133 | /** |
||
134 | * The subject's utility class with the SQL statements to use. |
||
135 | * |
||
136 | * @var string |
||
137 | * @Type("string") |
||
138 | * @SerializedName("utility-class-name") |
||
139 | */ |
||
140 | protected $utilityClassName; |
||
141 | |||
142 | /** |
||
143 | * The source date format to use in the subject. |
||
144 | * |
||
145 | * @var string |
||
146 | * @Type("string") |
||
147 | * @SerializedName("source-date-format") |
||
148 | */ |
||
149 | protected $sourceDateFormat = 'n/d/y, g:i A'; |
||
150 | |||
151 | /** |
||
152 | * The subject's multiple field delimiter character for fields with multiple values, defaults to (,). |
||
153 | * |
||
154 | * @var string |
||
155 | * @Type("string") |
||
156 | * @SerializedName("multiple-field-delimiter") |
||
157 | */ |
||
158 | protected $multipleFieldDelimiter = ','; |
||
159 | |||
160 | /** |
||
161 | * The subject's delimiter character for CSV files. |
||
162 | * |
||
163 | * @var string |
||
164 | * @Type("string") |
||
165 | */ |
||
166 | protected $delimiter; |
||
167 | |||
168 | /** |
||
169 | * The subject's enclosure character for CSV files. |
||
170 | * |
||
171 | * @var string |
||
172 | * @Type("string") |
||
173 | */ |
||
174 | protected $enclosure; |
||
175 | |||
176 | /** |
||
177 | * The subject's escape character for CSV files. |
||
178 | * |
||
179 | * @var string |
||
180 | * @Type("string") |
||
181 | */ |
||
182 | protected $escape; |
||
183 | |||
184 | /** |
||
185 | * The subject's source charset for the CSV file. |
||
186 | * |
||
187 | * @var string |
||
188 | * @Type("string") |
||
189 | * @SerializedName("from-charset") |
||
190 | */ |
||
191 | protected $fromCharset; |
||
192 | |||
193 | /** |
||
194 | * The subject's target charset for a CSV file. |
||
195 | * |
||
196 | * @var string |
||
197 | * @Type("string") |
||
198 | * @SerializedName("to-charset") |
||
199 | */ |
||
200 | protected $toCharset; |
||
201 | |||
202 | /** |
||
203 | * The subject's file mode for a CSV target file. |
||
204 | * |
||
205 | * @var string |
||
206 | * @Type("string") |
||
207 | * @SerializedName("file-mode") |
||
208 | */ |
||
209 | protected $fileMode; |
||
210 | |||
211 | /** |
||
212 | * The flag to signal that the subject has to use the strict mode or not. |
||
213 | * |
||
214 | * @var boolean |
||
215 | * @Type("boolean") |
||
216 | * @SerializedName("strict-mode") |
||
217 | */ |
||
218 | protected $strictMode; |
||
219 | |||
220 | /** |
||
221 | * The flag whether or not the import artefacts have to be archived. |
||
222 | * |
||
223 | * @var boolean |
||
224 | * @Type("boolean") |
||
225 | * @SerializedName("archive-artefacts") |
||
226 | */ |
||
227 | protected $archiveArtefacts; |
||
228 | |||
229 | /** |
||
230 | * The directory where the archives will be stored. |
||
231 | * |
||
232 | * @var string |
||
233 | * @Type("string") |
||
234 | * @SerializedName("archive-dir") |
||
235 | */ |
||
236 | protected $archiveDir; |
||
237 | |||
238 | /** |
||
239 | * The flag to signal that the subject has to use the debug mode or not. |
||
240 | * |
||
241 | * @var boolean |
||
242 | * @Type("boolean") |
||
243 | * @SerializedName("debug-mode") |
||
244 | */ |
||
245 | protected $debugMode = false; |
||
246 | |||
247 | /** |
||
248 | * The flag to signal that the an existing PID should be ignored, whether or import process is running or not. |
||
249 | * |
||
250 | * @var boolean |
||
251 | * @Type("boolean") |
||
252 | * @SerializedName("ignore-pid") |
||
253 | */ |
||
254 | protected $ignorePid = false; |
||
255 | |||
256 | /** |
||
257 | * The log level to use (see Monolog documentation). |
||
258 | * |
||
259 | * @var string |
||
260 | * @Type("string") |
||
261 | * @SerializedName("log-level") |
||
262 | */ |
||
263 | protected $logLevel = LogLevel::INFO; |
||
264 | |||
265 | /** |
||
266 | * The explicit DB ID to use. |
||
267 | * |
||
268 | * @var string |
||
269 | * @Type("string") |
||
270 | * @SerializedName("use-db-id") |
||
271 | */ |
||
272 | protected $useDbId; |
||
273 | |||
274 | /** |
||
275 | * The explicit PID filename to use. |
||
276 | * |
||
277 | * @var string |
||
278 | * @Type("string") |
||
279 | * @SerializedName("pid-filename") |
||
280 | */ |
||
281 | protected $pidFilename; |
||
282 | |||
283 | /** |
||
284 | * Return's the array with the subjects of the operation to use. |
||
285 | * |
||
286 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the subjects |
||
287 | * @throws \Exception Is thrown, if no subjects are available for the actual operation |
||
288 | */ |
||
289 | public function getSubjects() |
||
303 | |||
304 | /** |
||
305 | * Map's the passed value to a boolean. |
||
306 | * |
||
307 | * @param string $value The value to map |
||
308 | * |
||
309 | * @return boolean The mapped value |
||
310 | * @throws \Exception Is thrown, if the value can't be mapped |
||
311 | */ |
||
312 | public function mapBoolean($value) |
||
323 | |||
324 | /** |
||
325 | * Return's the operation, initialize from the actual operation name. |
||
326 | * |
||
327 | * @return \TechDivision\Import\Configuration\OperationInterface The operation instance |
||
328 | */ |
||
329 | protected function getOperation() |
||
333 | |||
334 | /** |
||
335 | * Return's the operation name that has to be used. |
||
336 | * |
||
337 | * @param string $operationName The operation name that has to be used |
||
338 | * |
||
339 | * @return void |
||
340 | */ |
||
341 | public function setOperationName($operationName) |
||
345 | |||
346 | /** |
||
347 | * Return's the operation name that has to be used. |
||
348 | * |
||
349 | * @return string The operation name that has to be used |
||
350 | */ |
||
351 | public function getOperationName() |
||
355 | |||
356 | /** |
||
357 | * Set's the Magento installation directory. |
||
358 | * |
||
359 | * @param string $installationDir The Magento installation directory |
||
360 | * |
||
361 | * @return void |
||
362 | */ |
||
363 | public function setInstallationDir($installationDir) |
||
367 | |||
368 | /** |
||
369 | * Return's the Magento installation directory. |
||
370 | * |
||
371 | * @return string The Magento installation directory |
||
372 | */ |
||
373 | public function getInstallationDir() |
||
377 | |||
378 | /** |
||
379 | * Set's the source directory that has to be watched for new files. |
||
380 | * |
||
381 | * @param string $sourceDir The source directory |
||
382 | * |
||
383 | * @return void |
||
384 | */ |
||
385 | public function setSourceDir($sourceDir) |
||
389 | |||
390 | /** |
||
391 | * Return's the source directory that has to be watched for new files. |
||
392 | * |
||
393 | * @return string The source directory |
||
394 | */ |
||
395 | public function getSourceDir() |
||
399 | |||
400 | /** |
||
401 | * Return's the target directory with the files that has been imported. |
||
402 | * |
||
403 | * @return string The target directory |
||
404 | */ |
||
405 | public function getTargetDir() |
||
409 | |||
410 | /** |
||
411 | * Set's the target directory with the files that has been imported. |
||
412 | * |
||
413 | * @param string $targetDir The target directory |
||
414 | * |
||
415 | * @return void |
||
416 | */ |
||
417 | public function setTargetDir($targetDir) |
||
421 | |||
422 | /** |
||
423 | * Return's the utility class with the SQL statements to use. |
||
424 | * |
||
425 | * @param string $utilityClassName The utility class name |
||
426 | * |
||
427 | * @return void |
||
428 | */ |
||
429 | public function setUtilityClassName($utilityClassName) |
||
433 | |||
434 | /** |
||
435 | * Return's the utility class with the SQL statements to use. |
||
436 | * |
||
437 | * @return string The utility class name |
||
438 | */ |
||
439 | public function getUtilityClassName() |
||
443 | |||
444 | /** |
||
445 | * Set's the Magento edition, EE or CE. |
||
446 | * |
||
447 | * @param string $magentoEdition The Magento edition |
||
448 | * |
||
449 | * @return void |
||
450 | */ |
||
451 | public function setMagentoEdition($magentoEdition) |
||
455 | |||
456 | /** |
||
457 | * Return's the Magento edition, EE or CE. |
||
458 | * |
||
459 | * @return string The Magento edition |
||
460 | */ |
||
461 | public function getMagentoEdition() |
||
465 | |||
466 | /** |
||
467 | * Return's the Magento version, e. g. 2.1.0. |
||
468 | * |
||
469 | * @param string $magentoVersion The Magento version |
||
470 | * |
||
471 | * @return void |
||
472 | */ |
||
473 | public function setMagentoVersion($magentoVersion) |
||
477 | |||
478 | /** |
||
479 | * Return's the Magento version, e. g. 2.1.0. |
||
480 | * |
||
481 | * @return string The Magento version |
||
482 | */ |
||
483 | public function getMagentoVersion() |
||
487 | |||
488 | /** |
||
489 | * Return's the subject's source date format to use. |
||
490 | * |
||
491 | * @return string The source date format |
||
492 | */ |
||
493 | public function getSourceDateFormat() |
||
497 | |||
498 | /** |
||
499 | * Set's the subject's source date format to use. |
||
500 | * |
||
501 | * @param string $sourceDateFormat The source date format |
||
502 | * |
||
503 | * @return void |
||
504 | */ |
||
505 | public function setSourceDateFormat($sourceDateFormat) |
||
509 | |||
510 | /** |
||
511 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
512 | * |
||
513 | * @return string The multiple field delimiter character |
||
514 | */ |
||
515 | public function getMultipleFieldDelimiter() |
||
519 | |||
520 | /** |
||
521 | * Return's the delimiter character to use, default value is comma (,). |
||
522 | * |
||
523 | * @return string The delimiter character |
||
524 | */ |
||
525 | public function getDelimiter() |
||
529 | |||
530 | /** |
||
531 | * The enclosure character to use, default value is double quotation ("). |
||
532 | * |
||
533 | * @return string The enclosure character |
||
534 | */ |
||
535 | public function getEnclosure() |
||
539 | |||
540 | /** |
||
541 | * The escape character to use, default value is backslash (\). |
||
542 | * |
||
543 | * @return string The escape character |
||
544 | */ |
||
545 | public function getEscape() |
||
549 | |||
550 | /** |
||
551 | * The file encoding of the CSV source file, default value is UTF-8. |
||
552 | * |
||
553 | * @return string The charset used by the CSV source file |
||
554 | */ |
||
555 | public function getFromCharset() |
||
559 | |||
560 | /** |
||
561 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
562 | * |
||
563 | * @return string The charset used by the CSV target file |
||
564 | */ |
||
565 | public function getToCharset() |
||
569 | |||
570 | /** |
||
571 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
572 | * |
||
573 | * @return string The file mode of the CSV target file |
||
574 | */ |
||
575 | public function getFileMode() |
||
579 | |||
580 | /** |
||
581 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
582 | * |
||
583 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
584 | */ |
||
585 | public function isStrictMode() |
||
589 | |||
590 | /** |
||
591 | * Remove's all configured database configuration. |
||
592 | * |
||
593 | * @return void |
||
594 | */ |
||
595 | public function clearDatabases() |
||
599 | |||
600 | /** |
||
601 | * Add's the passed database configuration. |
||
602 | * |
||
603 | * @param \TechDivision\Import\Configuration\DatabaseInterface $database The database configuration |
||
604 | * |
||
605 | * @return void |
||
606 | */ |
||
607 | public function addDatabase(DatabaseInterface $database) |
||
611 | |||
612 | /** |
||
613 | * Return's the database configuration. |
||
614 | * |
||
615 | * If an explicit DB ID is specified, the method tries to return the database with this ID. If |
||
616 | * the database configuration is NOT available, an execption is thrown. |
||
617 | * |
||
618 | * If no explicit DB ID is specified, the method tries to return the default database configuration, |
||
619 | * if not available the first one. |
||
620 | * |
||
621 | * @return \TechDivision\Import\Cli\Configuration\Database The database configuration |
||
622 | * @throws \Exception Is thrown, if no database configuration is available |
||
623 | */ |
||
624 | public function getDatabase() |
||
657 | |||
658 | /** |
||
659 | * Return's the ArrayCollection with the configured operations. |
||
660 | * |
||
661 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
662 | */ |
||
663 | public function getOperations() |
||
667 | |||
668 | /** |
||
669 | * Return's the TRUE if the import artefacts have to be archived. |
||
670 | * |
||
671 | * @return boolean TRUE if the import artefacts have to be archived |
||
672 | */ |
||
673 | public function haveArchiveArtefacts() |
||
677 | |||
678 | /** |
||
679 | * The directory where the archives will be stored. |
||
680 | * |
||
681 | * @return string The archive directory |
||
682 | */ |
||
683 | public function getArchiveDir() |
||
687 | |||
688 | /** |
||
689 | * Set's the debug mode. |
||
690 | * |
||
691 | * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE |
||
692 | * |
||
693 | * @return void |
||
694 | */ |
||
695 | public function setDebugMode($debugMode) |
||
699 | |||
700 | /** |
||
701 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
702 | * |
||
703 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
704 | */ |
||
705 | public function isDebugMode() |
||
709 | |||
710 | /** |
||
711 | * Set's the flag to signal that the an existing PID has to be ignored, whether a |
||
712 | * import process is running or not. |
||
713 | * |
||
714 | * @param boolean $ignorePid TRUE if the PID has to be ignored, else FALSE |
||
715 | * |
||
716 | * @return void |
||
717 | */ |
||
718 | public function setIgnorePid($ignorePid) |
||
722 | |||
723 | /** |
||
724 | * Queries whether or not that the an existing PID has to be ignored. |
||
725 | * |
||
726 | * @return boolean TRUE if an existing PID has to be ignored, else FALSE |
||
727 | */ |
||
728 | public function isIgnorePid() |
||
732 | |||
733 | /** |
||
734 | * Set's the log level to use. |
||
735 | * |
||
736 | * @param string $logLevel The log level to use |
||
737 | * |
||
738 | * @return void |
||
739 | */ |
||
740 | public function setLogLevel($logLevel) |
||
744 | |||
745 | /** |
||
746 | * Return's the log level to use. |
||
747 | * |
||
748 | * @return string The log level to use |
||
749 | */ |
||
750 | public function getLogLevel() |
||
754 | |||
755 | /** |
||
756 | * Set's the explicit DB ID to use. |
||
757 | * |
||
758 | * @param string $useDbId The explicit DB ID to use |
||
759 | * |
||
760 | * @return void |
||
761 | */ |
||
762 | public function setUseDbId($useDbId) |
||
766 | |||
767 | /** |
||
768 | * Return's the explicit DB ID to use. |
||
769 | * |
||
770 | * @return string The explicit DB ID to use |
||
771 | */ |
||
772 | public function getUseDbId() |
||
776 | |||
777 | /** |
||
778 | * Set's the PID filename to use. |
||
779 | * |
||
780 | * @param string $pidFilename The PID filename to use |
||
781 | * |
||
782 | * @return void |
||
783 | */ |
||
784 | public function setPidFilename($pidFilename) |
||
788 | |||
789 | /** |
||
790 | * Return's the PID filename to use. |
||
791 | * |
||
792 | * @return string The PID filename to use |
||
793 | */ |
||
794 | public function getPidFilename() |
||
798 | } |
||
799 |