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