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 system name to use. |
||
66 | * |
||
67 | * @var string |
||
68 | * @Type("string") |
||
69 | * @SerializedName("system-name") |
||
70 | */ |
||
71 | protected $systemName; |
||
72 | |||
73 | /** |
||
74 | * The operation name to use. |
||
75 | * |
||
76 | * @var string |
||
77 | * @Type("string") |
||
78 | * @SerializedName("operation-name") |
||
79 | */ |
||
80 | protected $operationName; |
||
81 | |||
82 | /** |
||
83 | * The entity type code to use. |
||
84 | * |
||
85 | * @var string |
||
86 | * @Type("string") |
||
87 | * @SerializedName("entity-type-code") |
||
88 | */ |
||
89 | protected $entityTypeCode; |
||
90 | |||
91 | /** |
||
92 | * The Magento installation directory. |
||
93 | * |
||
94 | * @var string |
||
95 | * @Type("string") |
||
96 | * @SerializedName("installation-dir") |
||
97 | */ |
||
98 | protected $installationDir; |
||
99 | |||
100 | /** |
||
101 | * The source directory that has to be watched for new files. |
||
102 | * |
||
103 | * @var string |
||
104 | * @Type("string") |
||
105 | * @SerializedName("source-dir") |
||
106 | */ |
||
107 | protected $sourceDir; |
||
108 | |||
109 | /** |
||
110 | * The target directory with the files that has been imported. |
||
111 | * |
||
112 | * @var string |
||
113 | * @Type("string") |
||
114 | * @SerializedName("target-dir") |
||
115 | */ |
||
116 | protected $targetDir; |
||
117 | |||
118 | /** |
||
119 | * The Magento edition, EE or CE. |
||
120 | * |
||
121 | * @var string |
||
122 | * @Type("string") |
||
123 | * @SerializedName("magento-edition") |
||
124 | */ |
||
125 | protected $magentoEdition = 'CE'; |
||
126 | |||
127 | /** |
||
128 | * The Magento version, e. g. 2.1.0. |
||
129 | * |
||
130 | * @var string |
||
131 | * @Type("string") |
||
132 | * @SerializedName("magento-version") |
||
133 | */ |
||
134 | protected $magentoVersion = '2.1.2'; |
||
135 | |||
136 | /** |
||
137 | * ArrayCollection with the information of the configured databases. |
||
138 | * |
||
139 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
140 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Database>") |
||
141 | */ |
||
142 | protected $databases; |
||
143 | |||
144 | /** |
||
145 | * ArrayCollection with the information of the configured loggers. |
||
146 | * |
||
147 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
148 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Logger>") |
||
149 | */ |
||
150 | protected $loggers = array(); |
||
151 | |||
152 | /** |
||
153 | * ArrayCollection with the information of the configured operations. |
||
154 | * |
||
155 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
156 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Operation>") |
||
157 | */ |
||
158 | protected $operations = array(); |
||
159 | |||
160 | /** |
||
161 | * The source date format to use in the subject. |
||
162 | * |
||
163 | * @var string |
||
164 | * @Type("string") |
||
165 | * @SerializedName("source-date-format") |
||
166 | */ |
||
167 | protected $sourceDateFormat = 'n/d/y, g:i A'; |
||
168 | |||
169 | /** |
||
170 | * The subject's multiple field delimiter character for fields with multiple values, defaults to (,). |
||
171 | * |
||
172 | * @var string |
||
173 | * @Type("string") |
||
174 | * @SerializedName("multiple-field-delimiter") |
||
175 | */ |
||
176 | protected $multipleFieldDelimiter = ','; |
||
177 | |||
178 | /** |
||
179 | * The subject's multiple value delimiter character for fields with multiple values, defaults to (|). |
||
180 | * |
||
181 | * @var string |
||
182 | * @Type("string") |
||
183 | * @SerializedName("multiple-value-delimiter") |
||
184 | */ |
||
185 | protected $multipleValueDelimiter = '|'; |
||
186 | |||
187 | /** |
||
188 | * The subject's delimiter character for CSV files. |
||
189 | * |
||
190 | * @var string |
||
191 | * @Type("string") |
||
192 | */ |
||
193 | protected $delimiter; |
||
194 | |||
195 | /** |
||
196 | * The subject's enclosure character for CSV files. |
||
197 | * |
||
198 | * @var string |
||
199 | * @Type("string") |
||
200 | */ |
||
201 | protected $enclosure; |
||
202 | |||
203 | /** |
||
204 | * The subject's escape character for CSV files. |
||
205 | * |
||
206 | * @var string |
||
207 | * @Type("string") |
||
208 | */ |
||
209 | protected $escape; |
||
210 | |||
211 | /** |
||
212 | * The subject's source charset for the CSV file. |
||
213 | * |
||
214 | * @var string |
||
215 | * @Type("string") |
||
216 | * @SerializedName("from-charset") |
||
217 | */ |
||
218 | protected $fromCharset; |
||
219 | |||
220 | /** |
||
221 | * The subject's target charset for a CSV file. |
||
222 | * |
||
223 | * @var string |
||
224 | * @Type("string") |
||
225 | * @SerializedName("to-charset") |
||
226 | */ |
||
227 | protected $toCharset; |
||
228 | |||
229 | /** |
||
230 | * The subject's file mode for a CSV target file. |
||
231 | * |
||
232 | * @var string |
||
233 | * @Type("string") |
||
234 | * @SerializedName("file-mode") |
||
235 | */ |
||
236 | protected $fileMode; |
||
237 | |||
238 | /** |
||
239 | * The flag to signal that the subject has to use the strict mode or not. |
||
240 | * |
||
241 | * @var boolean |
||
242 | * @Type("boolean") |
||
243 | * @SerializedName("strict-mode") |
||
244 | */ |
||
245 | protected $strictMode; |
||
246 | |||
247 | /** |
||
248 | * The flag whether or not the import artefacts have to be archived. |
||
249 | * |
||
250 | * @var boolean |
||
251 | * @Type("boolean") |
||
252 | * @SerializedName("archive-artefacts") |
||
253 | */ |
||
254 | protected $archiveArtefacts; |
||
255 | |||
256 | /** |
||
257 | * The directory where the archives will be stored. |
||
258 | * |
||
259 | * @var string |
||
260 | * @Type("string") |
||
261 | * @SerializedName("archive-dir") |
||
262 | */ |
||
263 | protected $archiveDir; |
||
264 | |||
265 | /** |
||
266 | * The flag to signal that the subject has to use the debug mode or not. |
||
267 | * |
||
268 | * @var boolean |
||
269 | * @Type("boolean") |
||
270 | * @SerializedName("debug-mode") |
||
271 | */ |
||
272 | protected $debugMode = false; |
||
273 | |||
274 | /** |
||
275 | * The log level to use (see Monolog documentation). |
||
276 | * |
||
277 | * @var string |
||
278 | * @Type("string") |
||
279 | * @SerializedName("log-level") |
||
280 | */ |
||
281 | protected $logLevel = LogLevel::INFO; |
||
282 | |||
283 | /** |
||
284 | * The explicit DB ID to use. |
||
285 | * |
||
286 | * @var string |
||
287 | * @Type("string") |
||
288 | * @SerializedName("use-db-id") |
||
289 | */ |
||
290 | protected $useDbId; |
||
291 | |||
292 | /** |
||
293 | * The explicit PID filename to use. |
||
294 | * |
||
295 | * @var string |
||
296 | * @Type("string") |
||
297 | * @SerializedName("pid-filename") |
||
298 | */ |
||
299 | protected $pidFilename; |
||
300 | |||
301 | /** |
||
302 | * The collection with the paths to additional vendor directories. |
||
303 | * |
||
304 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
305 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\VendorDir>") |
||
306 | * @SerializedName("additional-vendor-dirs") |
||
307 | */ |
||
308 | protected $additionalVendorDirs = array(); |
||
309 | |||
310 | /** |
||
311 | * The array with the Magento Edition specific extension libraries. |
||
312 | * |
||
313 | * @var array |
||
314 | * @Type("array") |
||
315 | * @SerializedName("extension-libraries") |
||
316 | */ |
||
317 | protected $extensionLibraries = array(); |
||
318 | |||
319 | /** |
||
320 | * Initializes the instance. |
||
321 | */ |
||
322 | public function __construct() |
||
326 | |||
327 | /** |
||
328 | * Return's the array with the plugins of the operation to use. |
||
329 | * |
||
330 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the plugins |
||
331 | * @throws \Exception Is thrown, if no plugins are available for the actual operation |
||
332 | */ |
||
333 | public function getPlugins() |
||
347 | |||
348 | /** |
||
349 | * Map's the passed value to a boolean. |
||
350 | * |
||
351 | * @param string $value The value to map |
||
352 | * |
||
353 | * @return boolean The mapped value |
||
354 | * @throws \Exception Is thrown, if the value can't be mapped |
||
355 | */ |
||
356 | public function mapBoolean($value) |
||
367 | |||
368 | /** |
||
369 | * Return's the operation, initialize from the actual operation name. |
||
370 | * |
||
371 | * @return \TechDivision\Import\Configuration\OperationInterface The operation instance |
||
372 | */ |
||
373 | protected function getOperation() |
||
377 | |||
378 | /** |
||
379 | * Return's the operation name that has to be used. |
||
380 | * |
||
381 | * @param string $operationName The operation name that has to be used |
||
382 | * |
||
383 | * @return void |
||
384 | */ |
||
385 | public function setOperationName($operationName) |
||
389 | |||
390 | /** |
||
391 | * Return's the operation name that has to be used. |
||
392 | * |
||
393 | * @return string The operation name that has to be used |
||
394 | */ |
||
395 | public function getOperationName() |
||
399 | |||
400 | /** |
||
401 | * Set's the Magento installation directory. |
||
402 | * |
||
403 | * @param string $installationDir The Magento installation directory |
||
404 | * |
||
405 | * @return void |
||
406 | */ |
||
407 | public function setInstallationDir($installationDir) |
||
411 | |||
412 | /** |
||
413 | * Return's the Magento installation directory. |
||
414 | * |
||
415 | * @return string The Magento installation directory |
||
416 | */ |
||
417 | public function getInstallationDir() |
||
421 | |||
422 | /** |
||
423 | * Set's the source directory that has to be watched for new files. |
||
424 | * |
||
425 | * @param string $sourceDir The source directory |
||
426 | * |
||
427 | * @return void |
||
428 | */ |
||
429 | public function setSourceDir($sourceDir) |
||
433 | |||
434 | /** |
||
435 | * Return's the source directory that has to be watched for new files. |
||
436 | * |
||
437 | * @return string The source directory |
||
438 | */ |
||
439 | public function getSourceDir() |
||
443 | |||
444 | /** |
||
445 | * Set's the target directory with the files that has been imported. |
||
446 | * |
||
447 | * @param string $targetDir The target directory |
||
448 | * |
||
449 | * @return void |
||
450 | */ |
||
451 | public function setTargetDir($targetDir) |
||
455 | |||
456 | /** |
||
457 | * Return's the target directory with the files that has been imported. |
||
458 | * |
||
459 | * @return string The target directory |
||
460 | */ |
||
461 | public function getTargetDir() |
||
465 | |||
466 | /** |
||
467 | * Set's the Magento edition, EE or CE. |
||
468 | * |
||
469 | * @param string $magentoEdition The Magento edition |
||
470 | * |
||
471 | * @return void |
||
472 | */ |
||
473 | public function setMagentoEdition($magentoEdition) |
||
477 | |||
478 | /** |
||
479 | * Return's the Magento edition, EE or CE. |
||
480 | * |
||
481 | * @return string The Magento edition |
||
482 | */ |
||
483 | public function getMagentoEdition() |
||
487 | |||
488 | /** |
||
489 | * Return's the Magento version, e. g. 2.1.0. |
||
490 | * |
||
491 | * @param string $magentoVersion The Magento version |
||
492 | * |
||
493 | * @return void |
||
494 | */ |
||
495 | public function setMagentoVersion($magentoVersion) |
||
499 | |||
500 | /** |
||
501 | * Return's the Magento version, e. g. 2.1.0. |
||
502 | * |
||
503 | * @return string The Magento version |
||
504 | */ |
||
505 | public function getMagentoVersion() |
||
509 | |||
510 | /** |
||
511 | * Return's the subject's source date format to use. |
||
512 | * |
||
513 | * @return string The source date format |
||
514 | */ |
||
515 | public function getSourceDateFormat() |
||
519 | |||
520 | /** |
||
521 | * Set's the subject's source date format to use. |
||
522 | * |
||
523 | * @param string $sourceDateFormat The source date format |
||
524 | * |
||
525 | * @return void |
||
526 | */ |
||
527 | public function setSourceDateFormat($sourceDateFormat) |
||
531 | |||
532 | /** |
||
533 | * Return's the entity type code to be used. |
||
534 | * |
||
535 | * @return string The entity type code to be used |
||
536 | */ |
||
537 | public function getEntityTypeCode() |
||
541 | |||
542 | /** |
||
543 | * Set's the entity type code to be used. |
||
544 | * |
||
545 | * @param string $entityTypeCode The entity type code |
||
546 | * |
||
547 | * @return void |
||
548 | */ |
||
549 | public function setEntityTypeCode($entityTypeCode) |
||
553 | |||
554 | /** |
||
555 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
556 | * |
||
557 | * @return string The multiple field delimiter character |
||
558 | */ |
||
559 | public function getMultipleFieldDelimiter() |
||
563 | |||
564 | /** |
||
565 | * Return's the multiple value delimiter character to use, default value is comma (|). |
||
566 | * |
||
567 | * @return string The multiple value delimiter character |
||
568 | */ |
||
569 | public function getMultipleValueDelimiter() |
||
573 | |||
574 | /** |
||
575 | * Return's the delimiter character to use, default value is comma (,). |
||
576 | * |
||
577 | * @return string The delimiter character |
||
578 | */ |
||
579 | public function getDelimiter() |
||
583 | |||
584 | /** |
||
585 | * The enclosure character to use, default value is double quotation ("). |
||
586 | * |
||
587 | * @return string The enclosure character |
||
588 | */ |
||
589 | public function getEnclosure() |
||
593 | |||
594 | /** |
||
595 | * The escape character to use, default value is backslash (\). |
||
596 | * |
||
597 | * @return string The escape character |
||
598 | */ |
||
599 | public function getEscape() |
||
603 | |||
604 | /** |
||
605 | * The file encoding of the CSV source file, default value is UTF-8. |
||
606 | * |
||
607 | * @return string The charset used by the CSV source file |
||
608 | */ |
||
609 | public function getFromCharset() |
||
613 | |||
614 | /** |
||
615 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
616 | * |
||
617 | * @return string The charset used by the CSV target file |
||
618 | */ |
||
619 | public function getToCharset() |
||
623 | |||
624 | /** |
||
625 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
626 | * |
||
627 | * @return string The file mode of the CSV target file |
||
628 | */ |
||
629 | public function getFileMode() |
||
633 | |||
634 | /** |
||
635 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
636 | * |
||
637 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
638 | */ |
||
639 | public function isStrictMode() |
||
643 | |||
644 | /** |
||
645 | * Remove's all configured database configuration. |
||
646 | * |
||
647 | * @return void |
||
648 | */ |
||
649 | public function clearDatabases() |
||
653 | |||
654 | /** |
||
655 | * Add's the passed database configuration. |
||
656 | * |
||
657 | * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration |
||
658 | * |
||
659 | * @return void |
||
660 | */ |
||
661 | public function addDatabase(DatabaseConfigurationInterface $database) |
||
665 | |||
666 | /** |
||
667 | * Return's the database configuration. |
||
668 | * |
||
669 | * If an explicit DB ID is specified, the method tries to return the database with this ID. If |
||
670 | * the database configuration is NOT available, an execption is thrown. |
||
671 | * |
||
672 | * If no explicit DB ID is specified, the method tries to return the default database configuration, |
||
673 | * if not available the first one. |
||
674 | * |
||
675 | * @return \TechDivision\Import\Configuration\Jms\Configuration\Database The database configuration |
||
676 | * @throws \Exception Is thrown, if no database configuration is available |
||
677 | */ |
||
678 | public function getDatabase() |
||
711 | |||
712 | /** |
||
713 | * Return's the ArrayCollection with the configured operations. |
||
714 | * |
||
715 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
716 | */ |
||
717 | public function getOperations() |
||
721 | |||
722 | /** |
||
723 | * Return's the ArrayCollection with the configured loggers. |
||
724 | * |
||
725 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the loggers |
||
726 | */ |
||
727 | public function getLoggers() |
||
731 | |||
732 | /** |
||
733 | * Return's the TRUE if the import artefacts have to be archived. |
||
734 | * |
||
735 | * @return boolean TRUE if the import artefacts have to be archived |
||
736 | */ |
||
737 | public function haveArchiveArtefacts() |
||
741 | |||
742 | /** |
||
743 | * The directory where the archives will be stored. |
||
744 | * |
||
745 | * @return string The archive directory |
||
746 | */ |
||
747 | public function getArchiveDir() |
||
751 | |||
752 | /** |
||
753 | * Set's the debug mode. |
||
754 | * |
||
755 | * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE |
||
756 | * |
||
757 | * @return void |
||
758 | */ |
||
759 | public function setDebugMode($debugMode) |
||
763 | |||
764 | /** |
||
765 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
766 | * |
||
767 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
768 | */ |
||
769 | public function isDebugMode() |
||
773 | |||
774 | /** |
||
775 | * Set's the log level to use. |
||
776 | * |
||
777 | * @param string $logLevel The log level to use |
||
778 | * |
||
779 | * @return void |
||
780 | */ |
||
781 | public function setLogLevel($logLevel) |
||
785 | |||
786 | /** |
||
787 | * Return's the log level to use. |
||
788 | * |
||
789 | * @return string The log level to use |
||
790 | */ |
||
791 | public function getLogLevel() |
||
795 | |||
796 | /** |
||
797 | * Set's the explicit DB ID to use. |
||
798 | * |
||
799 | * @param string $useDbId The explicit DB ID to use |
||
800 | * |
||
801 | * @return void |
||
802 | */ |
||
803 | public function setUseDbId($useDbId) |
||
807 | |||
808 | /** |
||
809 | * Return's the explicit DB ID to use. |
||
810 | * |
||
811 | * @return string The explicit DB ID to use |
||
812 | */ |
||
813 | public function getUseDbId() |
||
817 | |||
818 | /** |
||
819 | * Set's the PID filename to use. |
||
820 | * |
||
821 | * @param string $pidFilename The PID filename to use |
||
822 | * |
||
823 | * @return void |
||
824 | */ |
||
825 | public function setPidFilename($pidFilename) |
||
829 | |||
830 | /** |
||
831 | * Return's the PID filename to use. |
||
832 | * |
||
833 | * @return string The PID filename to use |
||
834 | */ |
||
835 | public function getPidFilename() |
||
839 | |||
840 | /** |
||
841 | * Set's the systemm name to be used. |
||
842 | * |
||
843 | * @param string $systemName The system name to be used |
||
844 | * |
||
845 | * @return void |
||
846 | */ |
||
847 | public function setSystemName($systemName) |
||
851 | |||
852 | /** |
||
853 | * Return's the systemm name to be used. |
||
854 | * |
||
855 | * @return string The system name to be used |
||
856 | */ |
||
857 | public function getSystemName() |
||
861 | |||
862 | /** |
||
863 | * Return's a collection with the path to additional vendor directories. |
||
864 | * |
||
865 | * @return \Doctrine\Common\Collections\ArrayCollection The paths to additional vendor directories |
||
866 | */ |
||
867 | public function getAdditionalVendorDirs() |
||
871 | |||
872 | /** |
||
873 | * Return's an array with the path of the Magento Edition specific extension libraries. |
||
874 | * |
||
875 | * @return array The paths of the Magento Edition specific extension libraries |
||
876 | */ |
||
877 | public function getExtensionLibraries() |
||
881 | } |
||
882 |