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 |
||
38 | class Configuration implements ConfigurationInterface |
||
39 | { |
||
40 | |||
41 | /** |
||
42 | * Mapping for boolean values passed on the console. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $booleanMapping = array( |
||
47 | 'true' => true, |
||
48 | 'false' => false, |
||
49 | '1' => true, |
||
50 | '0' => false, |
||
51 | 'on' => true, |
||
52 | 'off' => false |
||
53 | ); |
||
54 | |||
55 | /** |
||
56 | * The operation name to use. |
||
57 | * |
||
58 | * @var string |
||
59 | * @Type("string") |
||
60 | * @SerializedName("operation-name") |
||
61 | */ |
||
62 | protected $operationName; |
||
63 | |||
64 | /** |
||
65 | * The Magento edition, EE or CE. |
||
66 | * |
||
67 | * @var string |
||
68 | * @Type("string") |
||
69 | * @SerializedName("magento-edition") |
||
70 | */ |
||
71 | protected $magentoEdition = 'CE'; |
||
72 | |||
73 | /** |
||
74 | * The Magento version, e. g. 2.1.0. |
||
75 | * |
||
76 | * @var string |
||
77 | * @Type("string") |
||
78 | * @SerializedName("magento-version") |
||
79 | */ |
||
80 | protected $magentoVersion = '2.1.2'; |
||
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 | * ArrayCollection with the information of the configured databases. |
||
111 | * |
||
112 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
113 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Database>") |
||
114 | */ |
||
115 | protected $databases; |
||
116 | |||
117 | /** |
||
118 | * ArrayCollection with the information of the configured operations. |
||
119 | * |
||
120 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
121 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Operation>") |
||
122 | */ |
||
123 | protected $operations; |
||
124 | |||
125 | /** |
||
126 | * The subject's utility class with the SQL statements to use. |
||
127 | * |
||
128 | * @var string |
||
129 | * @Type("string") |
||
130 | * @SerializedName("utility-class-name") |
||
131 | */ |
||
132 | protected $utilityClassName; |
||
133 | |||
134 | /** |
||
135 | * The source date format to use in the subject. |
||
136 | * |
||
137 | * @var string |
||
138 | * @Type("string") |
||
139 | * @SerializedName("source-date-format") |
||
140 | */ |
||
141 | protected $sourceDateFormat = 'n/d/y, g:i A'; |
||
142 | |||
143 | /** |
||
144 | * The subject's multiple field delimiter character for fields with multiple values, defaults to (,). |
||
145 | * |
||
146 | * @var string |
||
147 | * @Type("string") |
||
148 | * @SerializedName("multiple-field-delimiter") |
||
149 | */ |
||
150 | protected $multipleFieldDelimiter = ','; |
||
151 | |||
152 | /** |
||
153 | * The subject's delimiter character for CSV files. |
||
154 | * |
||
155 | * @var string |
||
156 | * @Type("string") |
||
157 | */ |
||
158 | protected $delimiter; |
||
159 | |||
160 | /** |
||
161 | * The subject's enclosure character for CSV files. |
||
162 | * |
||
163 | * @var string |
||
164 | * @Type("string") |
||
165 | */ |
||
166 | protected $enclosure; |
||
167 | |||
168 | /** |
||
169 | * The subject's escape character for CSV files. |
||
170 | * |
||
171 | * @var string |
||
172 | * @Type("string") |
||
173 | */ |
||
174 | protected $escape; |
||
175 | |||
176 | /** |
||
177 | * The subject's source charset for the CSV file. |
||
178 | * |
||
179 | * @var string |
||
180 | * @Type("string") |
||
181 | * @SerializedName("from-charset") |
||
182 | */ |
||
183 | protected $fromCharset; |
||
184 | |||
185 | /** |
||
186 | * The subject's target charset for a CSV file. |
||
187 | * |
||
188 | * @var string |
||
189 | * @Type("string") |
||
190 | * @SerializedName("to-charset") |
||
191 | */ |
||
192 | protected $toCharset; |
||
193 | |||
194 | /** |
||
195 | * The subject's file mode for a CSV target file. |
||
196 | * |
||
197 | * @var string |
||
198 | * @Type("string") |
||
199 | * @SerializedName("file-mode") |
||
200 | */ |
||
201 | protected $fileMode; |
||
202 | |||
203 | /** |
||
204 | * The flag to signal that the subject has to use the strict mode or not. |
||
205 | * |
||
206 | * @var boolean |
||
207 | * @Type("boolean") |
||
208 | * @SerializedName("strict-mode") |
||
209 | */ |
||
210 | protected $strictMode; |
||
211 | |||
212 | /** |
||
213 | * The flag whether or not the import artefacts have to be archived. |
||
214 | * |
||
215 | * @var boolean |
||
216 | * @Type("boolean") |
||
217 | * @SerializedName("archive-artefacts") |
||
218 | */ |
||
219 | protected $archiveArtefacts; |
||
220 | |||
221 | /** |
||
222 | * The directory where the archives will be stored. |
||
223 | * |
||
224 | * @var string |
||
225 | * @Type("string") |
||
226 | * @SerializedName("archive-dir") |
||
227 | */ |
||
228 | protected $archiveDir; |
||
229 | |||
230 | /** |
||
231 | * The flag to signal that the subject has to use the debug mode or not. |
||
232 | * |
||
233 | * @var boolean |
||
234 | * @Type("boolean") |
||
235 | * @SerializedName("debug-mode") |
||
236 | */ |
||
237 | protected $debugMode = false; |
||
238 | |||
239 | /** |
||
240 | * The flag to signal that the an existing PID should be ignored, whether or import process is running or not. |
||
241 | * |
||
242 | * @var boolean |
||
243 | * @Type("boolean") |
||
244 | * @SerializedName("ignore-pid") |
||
245 | */ |
||
246 | protected $ignorePid = false; |
||
247 | |||
248 | /** |
||
249 | * The log level to use (see Monolog documentation). |
||
250 | * |
||
251 | * @var string |
||
252 | * @Type("string") |
||
253 | * @SerializedName("log-level") |
||
254 | */ |
||
255 | protected $logLevel = LogLevel::INFO; |
||
256 | |||
257 | /** |
||
258 | * Return's the array with the subjects of the operation to use. |
||
259 | * |
||
260 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the subjects |
||
261 | * @throws \Exception Is thrown, if no subjects are available for the actual operation |
||
262 | */ |
||
263 | public function getSubjects() |
||
277 | |||
278 | /** |
||
279 | * Map's the passed value to a boolean. |
||
280 | * |
||
281 | * @param string $value The value to map |
||
282 | * |
||
283 | * @return boolean The mapped value |
||
284 | * @throws \Exception Is thrown, if the value can't be mapped |
||
285 | */ |
||
286 | public function mapBoolean($value) |
||
297 | |||
298 | /** |
||
299 | * Return's the operation, initialize from the actual operation name. |
||
300 | * |
||
301 | * @return \TechDivision\Import\Configuration\OperationInterface The operation instance |
||
302 | */ |
||
303 | protected function getOperation() |
||
307 | |||
308 | /** |
||
309 | * Return's the operation name that has to be used. |
||
310 | * |
||
311 | * @param string $operationName The operation name that has to be used |
||
312 | * |
||
313 | * @return void |
||
314 | */ |
||
315 | public function setOperationName($operationName) |
||
319 | |||
320 | /** |
||
321 | * Return's the operation name that has to be used. |
||
322 | * |
||
323 | * @return string The operation name that has to be used |
||
324 | */ |
||
325 | public function getOperationName() |
||
329 | |||
330 | /** |
||
331 | * Set's the Magento installation directory. |
||
332 | * |
||
333 | * @param string $installationDir The Magento installation directory |
||
334 | * |
||
335 | * @return void |
||
336 | */ |
||
337 | public function setInstallationDir($installationDir) |
||
341 | |||
342 | /** |
||
343 | * Return's the Magento installation directory. |
||
344 | * |
||
345 | * @return string The Magento installation directory |
||
346 | */ |
||
347 | public function getInstallationDir() |
||
351 | |||
352 | /** |
||
353 | * Set's the source directory that has to be watched for new files. |
||
354 | * |
||
355 | * @param string $sourceDir The source directory |
||
356 | * |
||
357 | * @return void |
||
358 | */ |
||
359 | public function setSourceDir($sourceDir) |
||
363 | |||
364 | /** |
||
365 | * Return's the source directory that has to be watched for new files. |
||
366 | * |
||
367 | * @return string The source directory |
||
368 | */ |
||
369 | public function getSourceDir() |
||
373 | |||
374 | /** |
||
375 | * Return's the target directory with the files that has been imported. |
||
376 | * |
||
377 | * @return string The target directory |
||
378 | */ |
||
379 | public function getTargetDir() |
||
383 | |||
384 | /** |
||
385 | * Set's the target directory with the files that has been imported. |
||
386 | * |
||
387 | * @param string $targetDir The target directory |
||
388 | * |
||
389 | * @return void |
||
390 | */ |
||
391 | public function setTargetDir($targetDir) |
||
395 | |||
396 | /** |
||
397 | * Return's the utility class with the SQL statements to use. |
||
398 | * |
||
399 | * @param string $utilityClassName The utility class name |
||
400 | * |
||
401 | * @return void |
||
402 | */ |
||
403 | public function setUtilityClassName($utilityClassName) |
||
407 | |||
408 | /** |
||
409 | * Return's the utility class with the SQL statements to use. |
||
410 | * |
||
411 | * @return string The utility class name |
||
412 | */ |
||
413 | public function getUtilityClassName() |
||
417 | |||
418 | /** |
||
419 | * Set's the Magento edition, EE or CE. |
||
420 | * |
||
421 | * @param string $magentoEdition The Magento edition |
||
422 | * |
||
423 | * @return void |
||
424 | */ |
||
425 | public function setMagentoEdition($magentoEdition) |
||
429 | |||
430 | /** |
||
431 | * Return's the Magento edition, EE or CE. |
||
432 | * |
||
433 | * @return string The Magento edition |
||
434 | */ |
||
435 | public function getMagentoEdition() |
||
439 | |||
440 | /** |
||
441 | * Return's the Magento version, e. g. 2.1.0. |
||
442 | * |
||
443 | * @param string $magentoVersion The Magento version |
||
444 | * |
||
445 | * @return void |
||
446 | */ |
||
447 | public function setMagentoVersion($magentoVersion) |
||
451 | |||
452 | /** |
||
453 | * Return's the Magento version, e. g. 2.1.0. |
||
454 | * |
||
455 | * @return string The Magento version |
||
456 | */ |
||
457 | public function getMagentoVersion() |
||
461 | |||
462 | /** |
||
463 | * Return's the subject's source date format to use. |
||
464 | * |
||
465 | * @return string The source date format |
||
466 | */ |
||
467 | public function getSourceDateFormat() |
||
471 | |||
472 | /** |
||
473 | * Set's the subject's source date format to use. |
||
474 | * |
||
475 | * @param string $sourceDateFormat The source date format |
||
476 | * |
||
477 | * @return void |
||
478 | */ |
||
479 | public function setSourceDateFormat($sourceDateFormat) |
||
483 | |||
484 | /** |
||
485 | * Return's the multiple field delimiter character to use, default value is comma (,). |
||
486 | * |
||
487 | * @return string The multiple field delimiter character |
||
488 | */ |
||
489 | public function getMultipleFieldDelimiter() |
||
493 | |||
494 | /** |
||
495 | * Return's the delimiter character to use, default value is comma (,). |
||
496 | * |
||
497 | * @return string The delimiter character |
||
498 | */ |
||
499 | public function getDelimiter() |
||
503 | |||
504 | /** |
||
505 | * The enclosure character to use, default value is double quotation ("). |
||
506 | * |
||
507 | * @return string The enclosure character |
||
508 | */ |
||
509 | public function getEnclosure() |
||
513 | |||
514 | /** |
||
515 | * The escape character to use, default value is backslash (\). |
||
516 | * |
||
517 | * @return string The escape character |
||
518 | */ |
||
519 | public function getEscape() |
||
523 | |||
524 | /** |
||
525 | * The file encoding of the CSV source file, default value is UTF-8. |
||
526 | * |
||
527 | * @return string The charset used by the CSV source file |
||
528 | */ |
||
529 | public function getFromCharset() |
||
533 | |||
534 | /** |
||
535 | * The file encoding of the CSV targetfile, default value is UTF-8. |
||
536 | * |
||
537 | * @return string The charset used by the CSV target file |
||
538 | */ |
||
539 | public function getToCharset() |
||
543 | |||
544 | /** |
||
545 | * The file mode of the CSV target file, either one of write or append, default is write. |
||
546 | * |
||
547 | * @return string The file mode of the CSV target file |
||
548 | */ |
||
549 | public function getFileMode() |
||
553 | |||
554 | /** |
||
555 | * Queries whether or not strict mode is enabled or not, default is TRUE. |
||
556 | * |
||
557 | * @return boolean TRUE if strict mode is enabled, else FALSE |
||
558 | */ |
||
559 | public function isStrictMode() |
||
563 | |||
564 | /** |
||
565 | * Return's the database configuration. |
||
566 | * |
||
567 | * @param string $id The ID of the database connection to return |
||
568 | * |
||
569 | * @return \TechDivision\Import\Cli\Configuration\Database The database configuration |
||
570 | * @throws \Exception Is thrown, if the database with the passed ID is not configured |
||
571 | */ |
||
572 | public function getDatabase($id = null) |
||
597 | |||
598 | /** |
||
599 | * Return's the ArrayCollection with the configured operations. |
||
600 | * |
||
601 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
602 | */ |
||
603 | public function getOperations() |
||
607 | |||
608 | /** |
||
609 | * Return's the TRUE if the import artefacts have to be archived. |
||
610 | * |
||
611 | * @return boolean TRUE if the import artefacts have to be archived |
||
612 | */ |
||
613 | public function haveArchiveArtefacts() |
||
617 | |||
618 | /** |
||
619 | * The directory where the archives will be stored. |
||
620 | * |
||
621 | * @return string The archive directory |
||
622 | */ |
||
623 | public function getArchiveDir() |
||
627 | |||
628 | /** |
||
629 | * Set's the debug mode. |
||
630 | * |
||
631 | * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE |
||
632 | * |
||
633 | * @return void |
||
634 | */ |
||
635 | public function setDebugMode($debugMode) |
||
639 | |||
640 | /** |
||
641 | * Queries whether or not debug mode is enabled or not, default is TRUE. |
||
642 | * |
||
643 | * @return boolean TRUE if debug mode is enabled, else FALSE |
||
644 | */ |
||
645 | public function isDebugMode() |
||
649 | |||
650 | /** |
||
651 | * Set's the flag to signal that the an existing PID hast to be ignored, whether a |
||
652 | * import process is running or not. |
||
653 | * |
||
654 | * @param boolean $ignorePid TRUE if the PID has to be ignored, else FALSE |
||
655 | * |
||
656 | * @return void |
||
657 | */ |
||
658 | public function setIgnorePid($ignorePid) |
||
662 | |||
663 | /** |
||
664 | * Queries whether or not that the an existing PID has to be ignored. |
||
665 | * |
||
666 | * @return boolean TRUE if an existing PID has to be ignored, else FALSE |
||
667 | */ |
||
668 | public function isIgnorePid() |
||
672 | |||
673 | /** |
||
674 | * Set's the log level to use. |
||
675 | * |
||
676 | * @param string $logLevel The log level to use |
||
677 | * |
||
678 | * @return void |
||
679 | */ |
||
680 | public function setLogLevel($logLevel) |
||
684 | |||
685 | /** |
||
686 | * Return's the log level to use. |
||
687 | * |
||
688 | * @return string The log level to use |
||
689 | */ |
||
690 | public function getLogLevel() |
||
694 | } |
||
695 |