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 |
||
48 | class Configuration implements ConfigurationInterface |
||
49 | { |
||
50 | |||
51 | /** |
||
52 | * The default PID filename to use. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | const PID_FILENAME = 'importer.pid'; |
||
57 | |||
58 | /** |
||
59 | * Trait that provides CSV configuration functionality. |
||
60 | * |
||
61 | * @var \TechDivision\Import\Configuration\Jms\Configuration\CsvTrait |
||
62 | */ |
||
63 | use CsvTrait; |
||
64 | |||
65 | /** |
||
66 | * Trait that provides CSV configuration functionality. |
||
67 | * |
||
68 | * @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
||
69 | */ |
||
70 | use ParamsTrait; |
||
71 | |||
72 | /** |
||
73 | * Trait that provides CSV configuration functionality. |
||
74 | * |
||
75 | * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait |
||
76 | */ |
||
77 | use ListenersTrait; |
||
78 | |||
79 | /** |
||
80 | * Mapping for boolean values passed on the console. |
||
81 | * |
||
82 | * @var array |
||
83 | * @Exclude |
||
84 | */ |
||
85 | protected $booleanMapping = array( |
||
86 | 'true' => true, |
||
87 | 'false' => false, |
||
88 | '1' => true, |
||
89 | '0' => false, |
||
90 | 'on' => true, |
||
91 | 'off' => false |
||
92 | ); |
||
93 | |||
94 | /** |
||
95 | * The application's unique DI identifier. |
||
96 | * |
||
97 | * @var string |
||
98 | * @Type("string") |
||
99 | * @SerializedName("id") |
||
100 | */ |
||
101 | protected $id; |
||
102 | |||
103 | /** |
||
104 | * The system name to use. |
||
105 | * |
||
106 | * @var string |
||
107 | * @Type("string") |
||
108 | * @SerializedName("system-name") |
||
109 | */ |
||
110 | protected $systemName; |
||
111 | |||
112 | /** |
||
113 | * The operation name to use. |
||
114 | * |
||
115 | * @var string |
||
116 | * @Type("string") |
||
117 | * @SerializedName("operation-name") |
||
118 | */ |
||
119 | protected $operationName; |
||
120 | |||
121 | /** |
||
122 | * The entity type code to use. |
||
123 | * |
||
124 | * @var string |
||
125 | * @Type("string") |
||
126 | * @SerializedName("entity-type-code") |
||
127 | */ |
||
128 | protected $entityTypeCode; |
||
129 | |||
130 | /** |
||
131 | * The Magento installation directory. |
||
132 | * |
||
133 | * @var string |
||
134 | * @Type("string") |
||
135 | * @SerializedName("installation-dir") |
||
136 | */ |
||
137 | protected $installationDir; |
||
138 | |||
139 | /** |
||
140 | * The source directory that has to be watched for new files. |
||
141 | * |
||
142 | * @var string |
||
143 | * @Type("string") |
||
144 | * @SerializedName("source-dir") |
||
145 | */ |
||
146 | protected $sourceDir; |
||
147 | |||
148 | /** |
||
149 | * The target directory with the files that has been imported. |
||
150 | * |
||
151 | * @var string |
||
152 | * @Type("string") |
||
153 | * @SerializedName("target-dir") |
||
154 | */ |
||
155 | protected $targetDir; |
||
156 | |||
157 | /** |
||
158 | * The Magento edition, EE or CE. |
||
159 | * |
||
160 | * @var string |
||
161 | * @Type("string") |
||
162 | * @SerializedName("magento-edition") |
||
163 | */ |
||
164 | protected $magentoEdition = 'CE'; |
||
165 | |||
166 | /** |
||
167 | * The Magento version, e. g. 2.1.0. |
||
168 | * |
||
169 | * @var string |
||
170 | * @Type("string") |
||
171 | * @SerializedName("magento-version") |
||
172 | */ |
||
173 | protected $magentoVersion = '2.1.2'; |
||
174 | |||
175 | /** |
||
176 | * ArrayCollection with the information of the configured databases. |
||
177 | * |
||
178 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
179 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Database>") |
||
180 | */ |
||
181 | protected $databases; |
||
182 | |||
183 | /** |
||
184 | * ArrayCollection with the information of the configured loggers. |
||
185 | * |
||
186 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
187 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Logger>") |
||
188 | */ |
||
189 | protected $loggers; |
||
190 | |||
191 | /** |
||
192 | * ArrayCollection with the information of the configured operations. |
||
193 | * |
||
194 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
195 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Operation>") |
||
196 | */ |
||
197 | protected $operations; |
||
198 | |||
199 | /** |
||
200 | * The subject's multiple field delimiter character for fields with multiple values, defaults to (,). |
||
201 | * |
||
202 | * @var string |
||
203 | * @Type("string") |
||
204 | * @SerializedName("multiple-field-delimiter") |
||
205 | */ |
||
206 | protected $multipleFieldDelimiter = ','; |
||
207 | |||
208 | /** |
||
209 | * The subject's multiple value delimiter character for fields with multiple values, defaults to (|). |
||
210 | * |
||
211 | * @var string |
||
212 | * @Type("string") |
||
213 | * @SerializedName("multiple-value-delimiter") |
||
214 | */ |
||
215 | protected $multipleValueDelimiter = '|'; |
||
216 | |||
217 | /** |
||
218 | * The flag to signal that the subject has to use the strict mode or not. |
||
219 | * |
||
220 | * @var boolean |
||
221 | * @Type("boolean") |
||
222 | * @SerializedName("strict-mode") |
||
223 | */ |
||
224 | protected $strictMode; |
||
225 | |||
226 | /** |
||
227 | * The flag whether or not the import artefacts have to be archived. |
||
228 | * |
||
229 | * @var boolean |
||
230 | * @Type("boolean") |
||
231 | * @SerializedName("archive-artefacts") |
||
232 | */ |
||
233 | protected $archiveArtefacts; |
||
234 | |||
235 | /** |
||
236 | * The directory where the archives will be stored. |
||
237 | * |
||
238 | * @var string |
||
239 | * @Type("string") |
||
240 | * @SerializedName("archive-dir") |
||
241 | */ |
||
242 | protected $archiveDir; |
||
243 | |||
244 | /** |
||
245 | * The flag to signal that the subject has to use the debug mode or not. |
||
246 | * |
||
247 | * @var boolean |
||
248 | * @Type("boolean") |
||
249 | * @SerializedName("debug-mode") |
||
250 | */ |
||
251 | protected $debugMode = false; |
||
252 | |||
253 | /** |
||
254 | * The log level to use (see Monolog documentation). |
||
255 | * |
||
256 | * @var string |
||
257 | * @Type("string") |
||
258 | * @SerializedName("log-level") |
||
259 | */ |
||
260 | protected $logLevel = LogLevel::INFO; |
||
261 | |||
262 | /** |
||
263 | * The explicit DB ID to use. |
||
264 | * |
||
265 | * @var string |
||
266 | * @Type("string") |
||
267 | * @SerializedName("use-db-id") |
||
268 | */ |
||
269 | protected $useDbId; |
||
270 | |||
271 | /** |
||
272 | * The explicit PID filename to use. |
||
273 | * |
||
274 | * @var string |
||
275 | * @Type("string") |
||
276 | * @SerializedName("pid-filename") |
||
277 | */ |
||
278 | protected $pidFilename; |
||
279 | |||
280 | /** |
||
281 | * The collection with the paths to additional vendor directories. |
||
282 | * |
||
283 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
284 | * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\VendorDir>") |
||
285 | * @SerializedName("additional-vendor-dirs") |
||
286 | */ |
||
287 | protected $additionalVendorDirs; |
||
288 | |||
289 | /** |
||
290 | * The array with the Magento Edition specific extension libraries. |
||
291 | * |
||
292 | * @var array |
||
293 | * @Type("array") |
||
294 | * @SerializedName("extension-libraries") |
||
295 | */ |
||
296 | protected $extensionLibraries = array(); |
||
297 | |||
298 | /** |
||
299 | * The array with the custom header mappings. |
||
300 | * |
||
301 | * @var array |
||
302 | * @Type("array") |
||
303 | * @SerializedName("header-mappings") |
||
304 | */ |
||
305 | protected $headerMappings = array(); |
||
306 | |||
307 | /** |
||
308 | * The array with the custom image types. |
||
309 | * |
||
310 | * @var array |
||
311 | * @Type("array") |
||
312 | * @SerializedName("image-types") |
||
313 | */ |
||
314 | protected $imageTypes = array(); |
||
315 | |||
316 | /** |
||
317 | * The flag to signal that the should be wrapped within a single transation or not. |
||
318 | * |
||
319 | * @var boolean |
||
320 | * @Type("boolean") |
||
321 | * @SerializedName("single-transaction") |
||
322 | */ |
||
323 | protected $singleTransaction = false; |
||
324 | |||
325 | /** |
||
326 | * Return's the array with the plugins of the operation to use. |
||
327 | * |
||
328 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the plugins |
||
329 | * @throws \Exception Is thrown, if no plugins are available for the actual operation |
||
330 | */ |
||
331 | public function getPlugins() |
||
345 | |||
346 | /** |
||
347 | * Map's the passed value to a boolean. |
||
348 | * |
||
349 | * @param string $value The value to map |
||
350 | * |
||
351 | * @return boolean The mapped value |
||
352 | * @throws \Exception Is thrown, if the value can't be mapped |
||
353 | */ |
||
354 | public function mapBoolean($value) |
||
365 | |||
366 | /** |
||
367 | * Return's the operation, initialize from the actual operation name. |
||
368 | * |
||
369 | * @return \TechDivision\Import\Configuration\OperationConfigurationInterface The operation instance |
||
370 | */ |
||
371 | public function getOperation() |
||
375 | |||
376 | /** |
||
377 | * Return's the application's unique DI identifier. |
||
378 | * |
||
379 | * @return string The application's unique DI identifier |
||
380 | */ |
||
381 | public function getId() |
||
385 | |||
386 | /** |
||
387 | * Return's the operation name that has to be used. |
||
388 | * |
||
389 | * @param string $operationName The operation name that has to be used |
||
390 | * |
||
391 | * @return void |
||
392 | */ |
||
393 | public function setOperationName($operationName) |
||
397 | |||
398 | /** |
||
399 | * Return's the operation name that has to be used. |
||
400 | * |
||
401 | * @return string The operation name that has to be used |
||
402 | */ |
||
403 | public function getOperationName() |
||
407 | |||
408 | /** |
||
409 | * Set's the Magento installation directory. |
||
410 | * |
||
411 | * @param string $installationDir The Magento installation directory |
||
412 | * |
||
413 | * @return void |
||
414 | */ |
||
415 | public function setInstallationDir($installationDir) |
||
419 | |||
420 | /** |
||
421 | * Return's the Magento installation directory. |
||
422 | * |
||
423 | * @return string The Magento installation directory |
||
424 | */ |
||
425 | public function getInstallationDir() |
||
429 | |||
430 | /** |
||
431 | * Set's the source directory that has to be watched for new files. |
||
432 | * |
||
433 | * @param string $sourceDir The source directory |
||
434 | * |
||
435 | * @return void |
||
436 | */ |
||
437 | public function setSourceDir($sourceDir) |
||
441 | |||
442 | /** |
||
443 | * Return's the source directory that has to be watched for new files. |
||
444 | * |
||
445 | * @return string The source directory |
||
446 | */ |
||
447 | public function getSourceDir() |
||
451 | |||
452 | /** |
||
453 | * Set's the target directory with the files that has been imported. |
||
454 | * |
||
455 | * @param string $targetDir The target directory |
||
456 | * |
||
457 | * @return void |
||
458 | */ |
||
459 | public function setTargetDir($targetDir) |
||
463 | |||
464 | /** |
||
465 | * Return's the target directory with the files that has been imported. |
||
466 | * |
||
467 | * @return string The target directory |
||
468 | */ |
||
469 | public function getTargetDir() |
||
473 | |||
474 | /** |
||
475 | * Set's the Magento edition, EE or CE. |
||
476 | * |
||
477 | * @param string $magentoEdition The Magento edition |
||
478 | * |
||
479 | * @return void |
||
480 | */ |
||
481 | public function setMagentoEdition($magentoEdition) |
||
485 | |||
486 | /** |
||
487 | * Return's the Magento edition, EE or CE. |
||
488 | * |
||
489 | * @return string The Magento edition |
||
490 | */ |
||
491 | public function getMagentoEdition() |
||
495 | |||
496 | /** |
||
497 | * Return's the Magento version, e. g. 2.1.0. |
||
498 | * |
||
499 | * @param string $magentoVersion The Magento version |
||
500 | * |
||
501 | * @return void |
||
502 | */ |
||
503 | public function setMagentoVersion($magentoVersion) |
||
507 | |||
508 | /** |
||
509 | * Return's the Magento version, e. g. 2.1.0. |
||
510 | * |
||
511 | * @return string The Magento version |
||
512 | */ |
||
513 | public function getMagentoVersion() |
||
517 | |||
518 | /** |
||
519 | * Set's the subject's source date format to use. |
||
520 | * |
||
521 | * @param string $sourceDateFormat The source date format |
||
522 | * |
||
523 | * @return void |
||
524 | */ |
||
525 | public function setSourceDateFormat($sourceDateFormat) |
||
529 | |||
530 | /** |
||
531 | * Return's the entity type code to be used. |
||
532 | * |
||
533 | * @return string The entity type code to be used |
||
534 | */ |
||
535 | public function getEntityTypeCode() |
||
539 | |||
540 | /** |
||
541 | * Set's the entity type code to be used. |
||
542 | * |
||
543 | * @param string $entityTypeCode The entity type code |
||
544 | * |
||
545 | * @return void |
||
546 | */ |
||
547 | public function setEntityTypeCode($entityTypeCode) |
||
551 | |||
552 | /** |
||
553 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
554 | * |
||
555 | * @return string The multiple field delimiter character |
||
556 | */ |
||
557 | public function getMultipleFieldDelimiter() |
||
561 | |||
562 | /** |
||
563 | * Return's the multiple value delimiter character to use, default value is comma (|). |
||
564 | * |
||
565 | * @return string The multiple value delimiter character |
||
566 | */ |
||
567 | public function getMultipleValueDelimiter() |
||
571 | |||
572 | /** |
||
573 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
574 | * |
||
575 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
576 | */ |
||
577 | public function isStrictMode() |
||
581 | |||
582 | /** |
||
583 | * Remove's all configured database configuration. |
||
584 | * |
||
585 | * @return void |
||
586 | */ |
||
587 | public function clearDatabases() |
||
591 | |||
592 | /** |
||
593 | * Add's the passed database configuration. |
||
594 | * |
||
595 | * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration |
||
596 | * |
||
597 | * @return void |
||
598 | */ |
||
599 | public function addDatabase(DatabaseConfigurationInterface $database) |
||
603 | |||
604 | /** |
||
605 | * Return's the number database configurations. |
||
606 | * |
||
607 | * @return integer The number of database configurations |
||
608 | */ |
||
609 | public function countDatabases() |
||
613 | |||
614 | /** |
||
615 | * Return's the database configuration with the passed ID. |
||
616 | * |
||
617 | * @param string $id The ID of the database connection to return |
||
618 | * |
||
619 | * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration |
||
620 | * @throws \Exception Is thrown, if no database configuration is available |
||
621 | */ |
||
622 | public function getDatabaseById($id) |
||
636 | |||
637 | /** |
||
638 | * Return's the database configuration. |
||
639 | * |
||
640 | * If an explicit DB ID is specified, the method tries to return the database with this ID. If |
||
641 | * the database configuration is NOT available, an execption is thrown. |
||
642 | * |
||
643 | * If no explicit DB ID is specified, the method tries to return the default database configuration, |
||
644 | * if not available the first one. |
||
645 | * |
||
646 | * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration |
||
647 | * @throws \Exception Is thrown, if no database configuration is available |
||
648 | */ |
||
649 | public function getDatabase() |
||
673 | |||
674 | /** |
||
675 | * Return's the ArrayCollection with the configured operations. |
||
676 | * |
||
677 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
678 | */ |
||
679 | public function getOperations() |
||
683 | |||
684 | /** |
||
685 | * Return's the ArrayCollection with the configured loggers. |
||
686 | * |
||
687 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the loggers |
||
688 | */ |
||
689 | public function getLoggers() |
||
693 | |||
694 | /** |
||
695 | * Set's the flag that import artefacts have to be archived or not. |
||
696 | * |
||
697 | * @param boolean $archiveArtefacts TRUE if artefacts have to be archived, else FALSE |
||
698 | * |
||
699 | * @return void |
||
700 | */ |
||
701 | public function setArchiveArtefacts($archiveArtefacts) |
||
705 | |||
706 | /** |
||
707 | * Return's the TRUE if the import artefacts have to be archived. |
||
708 | * |
||
709 | * @return boolean TRUE if the import artefacts have to be archived |
||
710 | */ |
||
711 | public function haveArchiveArtefacts() |
||
715 | |||
716 | /** |
||
717 | * The directory where the archives will be stored. |
||
718 | * |
||
719 | * @param string $archiveDir The archive directory |
||
720 | * |
||
721 | * @return void |
||
722 | */ |
||
723 | public function setArchiveDir($archiveDir) |
||
727 | |||
728 | /** |
||
729 | * The directory where the archives will be stored. |
||
730 | * |
||
731 | * @return string The archive directory |
||
732 | */ |
||
733 | public function getArchiveDir() |
||
737 | |||
738 | /** |
||
739 | * Set's the debug mode. |
||
740 | * |
||
741 | * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE |
||
742 | * |
||
743 | * @return void |
||
744 | */ |
||
745 | public function setDebugMode($debugMode) |
||
749 | |||
750 | /** |
||
751 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
752 | * |
||
753 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
754 | */ |
||
755 | public function isDebugMode() |
||
759 | |||
760 | /** |
||
761 | * Set's the log level to use. |
||
762 | * |
||
763 | * @param string $logLevel The log level to use |
||
764 | * |
||
765 | * @return void |
||
766 | */ |
||
767 | public function setLogLevel($logLevel) |
||
771 | |||
772 | /** |
||
773 | * Return's the log level to use. |
||
774 | * |
||
775 | * @return string The log level to use |
||
776 | */ |
||
777 | public function getLogLevel() |
||
781 | |||
782 | /** |
||
783 | * Set's the explicit DB ID to use. |
||
784 | * |
||
785 | * @param string $useDbId The explicit DB ID to use |
||
786 | * |
||
787 | * @return void |
||
788 | */ |
||
789 | public function setUseDbId($useDbId) |
||
793 | |||
794 | /** |
||
795 | * Return's the explicit DB ID to use. |
||
796 | * |
||
797 | * @return string The explicit DB ID to use |
||
798 | */ |
||
799 | public function getUseDbId() |
||
803 | |||
804 | /** |
||
805 | * Set's the PID filename to use. |
||
806 | * |
||
807 | * @param string $pidFilename The PID filename to use |
||
808 | * |
||
809 | * @return void |
||
810 | */ |
||
811 | public function setPidFilename($pidFilename) |
||
815 | |||
816 | /** |
||
817 | * Return's the PID filename to use. |
||
818 | * |
||
819 | * @return string The PID filename to use |
||
820 | */ |
||
821 | public function getPidFilename() |
||
825 | |||
826 | /** |
||
827 | * Set's the systemm name to be used. |
||
828 | * |
||
829 | * @param string $systemName The system name to be used |
||
830 | * |
||
831 | * @return void |
||
832 | */ |
||
833 | public function setSystemName($systemName) |
||
837 | |||
838 | /** |
||
839 | * Return's the systemm name to be used. |
||
840 | * |
||
841 | * @return string The system name to be used |
||
842 | */ |
||
843 | public function getSystemName() |
||
847 | |||
848 | /** |
||
849 | * Set's the collection with the path of the Magento Edition specific extension libraries. |
||
850 | * |
||
851 | * @param array $extensionLibraries The paths of the Magento Edition specific extension libraries |
||
852 | * |
||
853 | * @return void |
||
854 | */ |
||
855 | public function setExtensionLibraries(array $extensionLibraries) |
||
859 | |||
860 | /** |
||
861 | * Return's an array with the path of the Magento Edition specific extension libraries. |
||
862 | * |
||
863 | * @return array The paths of the Magento Edition specific extension libraries |
||
864 | */ |
||
865 | public function getExtensionLibraries() |
||
869 | |||
870 | /** |
||
871 | * Return's a collection with the path to additional vendor directories. |
||
872 | * |
||
873 | * @return \Doctrine\Common\Collections\ArrayCollection The paths to additional vendor directories |
||
874 | */ |
||
875 | public function getAdditionalVendorDirs() |
||
879 | |||
880 | /** |
||
881 | * Lifecycle callback that will be invoked after deserialization. |
||
882 | * |
||
883 | * @return void |
||
884 | * @PostDeserialize |
||
885 | */ |
||
886 | public function postDeserialize() |
||
904 | |||
905 | /** |
||
906 | * The array with the subject's custom header mappings. |
||
907 | * |
||
908 | * @return array The custom header mappings |
||
909 | */ |
||
910 | public function getHeaderMappings() |
||
924 | |||
925 | /** |
||
926 | * The array with the subject's custom image types. |
||
927 | * |
||
928 | * @return array The custom image types |
||
929 | */ |
||
930 | public function getImageTypes() |
||
944 | |||
945 | /** |
||
946 | * Set's the flag that decides whether or not the import should be wrapped within a single transaction. |
||
947 | * |
||
948 | * @param boolean $singleTransaction TRUE if the import should be wrapped in a single transation, else FALSE |
||
949 | * |
||
950 | * @return void |
||
951 | */ |
||
952 | public function setSingleTransaction($singleTransaction) |
||
956 | |||
957 | /** |
||
958 | * Whether or not the import should be wrapped within a single transation. |
||
959 | * |
||
960 | * @return boolean TRUE if the import should be wrapped in a single transation, else FALSE |
||
961 | */ |
||
962 | public function isSingleTransaction() |
||
966 | } |
||
967 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: