Complex classes like GeneratorOptions 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 GeneratorOptions, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class GeneratorOptions extends AbstractYamlReader implements \JsonSerializable |
||
6 | { |
||
7 | /** |
||
8 | * Common values used as option's value |
||
9 | */ |
||
10 | const VALUE_CAT = 'cat'; |
||
11 | const VALUE_END = 'end'; |
||
12 | const VALUE_FALSE = false; |
||
13 | const VALUE_NONE = 'none'; |
||
14 | const VALUE_START = 'start'; |
||
15 | const VALUE_TRUE = true; |
||
16 | /** |
||
17 | * Possible option keys |
||
18 | * @var string |
||
19 | */ |
||
20 | const ADD_COMMENTS = 'add_comments'; |
||
21 | const ARRAYS_FOLDER = 'arrays_folder'; |
||
22 | const BASIC_LOGIN = 'basic_login'; |
||
23 | const BASIC_PASSWORD = 'basic_password'; |
||
24 | const CATEGORY = 'category'; |
||
25 | const COMPOSER_NAME = 'composer_name'; |
||
26 | const COMPOSER_SETTINGS = 'composer_settings'; |
||
27 | const DESTINATION = 'destination'; |
||
28 | const ENUMS_FOLDER = 'enums_folder'; |
||
29 | const GATHER_METHODS = 'gather_methods'; |
||
30 | const GENERATE_TUTORIAL_FILE = 'generate_tutorial_file'; |
||
31 | const GENERIC_CONSTANTS_NAME = 'generic_constants_names'; |
||
32 | const NAMESPACE_PREFIX = 'namespace_prefix'; |
||
33 | const ORIGIN = 'origin'; |
||
34 | const PREFIX = 'prefix'; |
||
35 | const PROXY_HOST = 'proxy_host'; |
||
36 | const PROXY_LOGIN = 'proxy_login'; |
||
37 | const PROXY_PASSWORD = 'proxy_password'; |
||
38 | const PROXY_PORT = 'proxy_port'; |
||
39 | const SERVICES_FOLDER = 'services_folder'; |
||
40 | const SOAP_CLIENT_CLASS = 'soap_client_class'; |
||
41 | const SOAP_OPTIONS = 'soap_options'; |
||
42 | const SRC_DIRNAME = 'src_dirname'; |
||
43 | const STANDALONE = 'standalone'; |
||
44 | const STRUCT_ARRAY_CLASS = 'struct_array_class'; |
||
45 | const STRUCT_CLASS = 'struct_class'; |
||
46 | const STRUCTS_FOLDER = 'structs_folder'; |
||
47 | const SUFFIX = 'suffix'; |
||
48 | const VALIDATION = 'validation'; |
||
49 | const SCHEMAS_SAVE = 'schemas_save'; |
||
50 | const SCHEMAS_FOLDER = 'schemas_folder'; |
||
51 | /** |
||
52 | * Generator's options |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $options; |
||
56 | /** |
||
57 | 50 | * @param string $filename |
|
58 | */ |
||
59 | 50 | protected function __construct($filename) |
|
64 | /** |
||
65 | * Parse options for generator |
||
66 | * @param string $filename options's file to parse |
||
67 | 50 | * @return GeneratorOptions |
|
68 | */ |
||
69 | 50 | protected function parseOptions($filename) |
|
79 | /** |
||
80 | * Returns the option value |
||
81 | * @throws \InvalidArgumentException |
||
82 | * @param string $optionName |
||
83 | 1470 | * @return mixed |
|
84 | */ |
||
85 | 1470 | public function getOptionValue($optionName) |
|
92 | /** |
||
93 | * Allows to add an option and set its value |
||
94 | * @throws \InvalidArgumentException |
||
95 | * @param string $optionName |
||
96 | 1120 | * @return GeneratorOptions |
|
97 | */ |
||
98 | 1120 | public function setOptionValue($optionName, $optionValue, array $values = []) |
|
112 | /** |
||
113 | * @throws \InvalidArgumentException |
||
114 | * @param string $filename options's file to parse |
||
115 | 1120 | * @return GeneratorOptions |
|
116 | */ |
||
117 | 1120 | public static function instance($filename = null) |
|
121 | /** |
||
122 | 455 | * @return string |
|
123 | */ |
||
124 | 455 | public static function getDefaultConfigurationPath() |
|
128 | /** |
||
129 | * Get category option value |
||
130 | 405 | * @return string |
|
131 | */ |
||
132 | 405 | public function getCategory() |
|
136 | /** |
||
137 | * Set current category option value |
||
138 | * @throws \InvalidArgumentException |
||
139 | * @param string $category |
||
140 | 45 | * @return GeneratorOptions |
|
141 | */ |
||
142 | 45 | public function setCategory($category) |
|
146 | /** |
||
147 | * Get add comments option value |
||
148 | 300 | * @return array |
|
149 | */ |
||
150 | 300 | public function getAddComments() |
|
154 | /** |
||
155 | * Set current add comments option value |
||
156 | * @throws \InvalidArgumentException |
||
157 | * @param array $addComments |
||
158 | 95 | * @return GeneratorOptions |
|
159 | */ |
||
160 | public function setAddComments(array $addComments = []) |
||
176 | /** |
||
177 | * Get gather methods option value |
||
178 | 420 | * @return string |
|
179 | */ |
||
180 | 420 | public function getGatherMethods() |
|
184 | /** |
||
185 | * Set current gather methods option value |
||
186 | * @throws \InvalidArgumentException |
||
187 | * @param string $gatherMethods |
||
188 | 40 | * @return GeneratorOptions |
|
189 | */ |
||
190 | 40 | public function setGatherMethods($gatherMethods) |
|
194 | /** |
||
195 | * Get generate tutorial file option value |
||
196 | 50 | * @return bool |
|
197 | */ |
||
198 | 50 | public function getGenerateTutorialFile() |
|
202 | /** |
||
203 | * Set current generate tutorial file option value |
||
204 | * @throws \InvalidArgumentException |
||
205 | * @param bool $generateTutorialFile |
||
206 | 75 | * @return GeneratorOptions |
|
207 | */ |
||
208 | 75 | public function setGenerateTutorialFile($generateTutorialFile) |
|
212 | /** |
||
213 | * Get namespace option value |
||
214 | 375 | * @return string |
|
215 | */ |
||
216 | 375 | public function getNamespace() |
|
220 | /** |
||
221 | * Set current namespace option value |
||
222 | * @throws \InvalidArgumentException |
||
223 | * @param string $namespace |
||
224 | 55 | * @return GeneratorOptions |
|
225 | */ |
||
226 | 55 | public function setNamespace($namespace) |
|
230 | /** |
||
231 | * Get generic constants name option value |
||
232 | 90 | * @return bool |
|
233 | */ |
||
234 | 90 | public function getGenericConstantsName() |
|
238 | /** |
||
239 | * Set current generic constants name option value |
||
240 | * @throws \InvalidArgumentException |
||
241 | * @param bool $genericConstantsName |
||
242 | 75 | * @return GeneratorOptions |
|
243 | */ |
||
244 | 75 | public function setGenericConstantsName($genericConstantsName) |
|
248 | /** |
||
249 | * Get standalone option value |
||
250 | 95 | * @return bool |
|
251 | */ |
||
252 | 95 | public function getStandalone() |
|
256 | /** |
||
257 | * Set current standalone option value |
||
258 | * @throws \InvalidArgumentException |
||
259 | * @param bool $standalone |
||
260 | 45 | * @return GeneratorOptions |
|
261 | */ |
||
262 | 45 | public function setStandalone($standalone) |
|
266 | /** |
||
267 | * Get validation option value |
||
268 | 175 | * @return bool |
|
269 | */ |
||
270 | 175 | public function getValidation() |
|
274 | /** |
||
275 | * Set current validation option value |
||
276 | * @throws \InvalidArgumentException |
||
277 | * @param bool $validation |
||
278 | 40 | * @return GeneratorOptions |
|
279 | */ |
||
280 | 40 | public function setValidation($validation) |
|
284 | /** |
||
285 | * Get struct class option value |
||
286 | 150 | * @return string |
|
287 | */ |
||
288 | 150 | public function getStructClass() |
|
292 | /** |
||
293 | * Set current struct class option value |
||
294 | * @throws \InvalidArgumentException |
||
295 | * @param string $structClass |
||
296 | 45 | * @return GeneratorOptions |
|
297 | */ |
||
298 | 45 | public function setStructClass($structClass) |
|
302 | /** |
||
303 | * Get struct array class option value |
||
304 | 60 | * @return string |
|
305 | */ |
||
306 | 60 | public function getStructArrayClass() |
|
310 | /** |
||
311 | * Set current struct array class option value |
||
312 | * @throws \InvalidArgumentException |
||
313 | * @param string $structArrayClass |
||
314 | 35 | * @return GeneratorOptions |
|
315 | */ |
||
316 | 35 | public function setStructArrayClass($structArrayClass) |
|
320 | /** |
||
321 | * Get struct array class option value |
||
322 | 135 | * @return string |
|
323 | */ |
||
324 | 135 | public function getSoapClientClass() |
|
328 | /** |
||
329 | * Set current struct array class option value |
||
330 | * @throws \InvalidArgumentException |
||
331 | * @param string $soapClientClass |
||
332 | 35 | * @return GeneratorOptions |
|
333 | */ |
||
334 | 35 | public function setSoapClientClass($soapClientClass) |
|
338 | /** |
||
339 | * Get origin option value |
||
340 | 775 | * @return string |
|
341 | */ |
||
342 | 775 | public function getOrigin() |
|
346 | /** |
||
347 | * Set current origin option value |
||
348 | * @throws \InvalidArgumentException |
||
349 | * @param string $origin |
||
350 | 410 | * @return GeneratorOptions |
|
351 | */ |
||
352 | 410 | public function setOrigin($origin) |
|
356 | /** |
||
357 | * Get destination option value |
||
358 | 430 | * @return string |
|
359 | */ |
||
360 | 430 | public function getDestination() |
|
364 | /** |
||
365 | * Set current destination option value |
||
366 | * @throws \InvalidArgumentException |
||
367 | * @param string $destination |
||
368 | 415 | * @return GeneratorOptions |
|
369 | */ |
||
370 | 415 | public function setDestination($destination) |
|
374 | /** |
||
375 | * Get src dirname option value |
||
376 | 370 | * @return string |
|
377 | */ |
||
378 | 370 | public function getSrcDirname() |
|
382 | /** |
||
383 | * Set current src dirname option value |
||
384 | * @throws \InvalidArgumentException |
||
385 | * @param string $srcDirname |
||
386 | 25 | * @return GeneratorOptions |
|
387 | */ |
||
388 | 25 | public function setSrcDirname($srcDirname) |
|
392 | /** |
||
393 | * Get prefix option value |
||
394 | 770 | * @return string |
|
395 | */ |
||
396 | 770 | public function getPrefix() |
|
400 | /** |
||
401 | * Set current prefix option value |
||
402 | * @throws \InvalidArgumentException |
||
403 | * @param string $prefix |
||
404 | 135 | * @return GeneratorOptions |
|
405 | */ |
||
406 | 135 | public function setPrefix($prefix) |
|
410 | /** |
||
411 | * Get suffix option value |
||
412 | 740 | * @return string |
|
413 | */ |
||
414 | 740 | public function getSuffix() |
|
418 | /** |
||
419 | * Set current suffix option value |
||
420 | * @throws \InvalidArgumentException |
||
421 | * @param string $suffix |
||
422 | 65 | * @return GeneratorOptions |
|
423 | */ |
||
424 | 65 | public function setSuffix($suffix) |
|
428 | /** |
||
429 | * Get basic login option value |
||
430 | 780 | * @return string |
|
431 | */ |
||
432 | 780 | public function getBasicLogin() |
|
436 | /** |
||
437 | * Set current basic login option value |
||
438 | * @throws \InvalidArgumentException |
||
439 | * @param string $basicLogin |
||
440 | 35 | * @return GeneratorOptions |
|
441 | */ |
||
442 | 35 | public function setBasicLogin($basicLogin) |
|
446 | /** |
||
447 | * Get basic password option value |
||
448 | 780 | * @return string |
|
449 | */ |
||
450 | 780 | public function getBasicPassword() |
|
454 | /** |
||
455 | * Set current basic password option value |
||
456 | * @throws \InvalidArgumentException |
||
457 | * @param string $basicPassword |
||
458 | 35 | * @return GeneratorOptions |
|
459 | */ |
||
460 | 35 | public function setBasicPassword($basicPassword) |
|
464 | /** |
||
465 | * Get basic proxy host option value |
||
466 | 780 | * @return string |
|
467 | */ |
||
468 | 780 | public function getProxyHost() |
|
472 | /** |
||
473 | * Set current proxy host option value |
||
474 | * @throws \InvalidArgumentException |
||
475 | * @param string $proxyHost |
||
476 | 35 | * @return GeneratorOptions |
|
477 | */ |
||
478 | 35 | public function setProxyHost($proxyHost) |
|
482 | /** |
||
483 | * Get basic proxy port option value |
||
484 | 780 | * @return string |
|
485 | */ |
||
486 | 780 | public function getProxyPort() |
|
490 | /** |
||
491 | * Set current proxy port option value |
||
492 | * @throws \InvalidArgumentException |
||
493 | * @param string $proxyPort |
||
494 | 35 | * @return GeneratorOptions |
|
495 | */ |
||
496 | 35 | public function setProxyPort($proxyPort) |
|
500 | /** |
||
501 | * Get basic proxy login option value |
||
502 | 780 | * @return string |
|
503 | */ |
||
504 | 780 | public function getProxyLogin() |
|
508 | /** |
||
509 | * Set current proxy login option value |
||
510 | * @throws \InvalidArgumentException |
||
511 | * @param string $proxyLogin |
||
512 | 35 | * @return GeneratorOptions |
|
513 | */ |
||
514 | 35 | public function setProxyLogin($proxyLogin) |
|
518 | /** |
||
519 | * Get basic proxy password option value |
||
520 | 780 | * @return string |
|
521 | */ |
||
522 | 780 | public function getProxyPassword() |
|
526 | /** |
||
527 | * Set current proxy password option value |
||
528 | * @throws \InvalidArgumentException |
||
529 | * @param string $proxyPassword |
||
530 | 35 | * @return GeneratorOptions |
|
531 | */ |
||
532 | 35 | public function setProxyPassword($proxyPassword) |
|
536 | /** |
||
537 | * Get basic soap options option value |
||
538 | 770 | * @return array |
|
539 | */ |
||
540 | 770 | public function getSoapOptions() |
|
544 | /** |
||
545 | * Set current soap options option value |
||
546 | * @throws \InvalidArgumentException |
||
547 | * @param array $soapOptions |
||
548 | 40 | * @return GeneratorOptions |
|
549 | */ |
||
550 | 40 | public function setSoapOptions(array $soapOptions) |
|
554 | /** |
||
555 | * Get composer name option value |
||
556 | 75 | * @return string |
|
557 | */ |
||
558 | 75 | public function getComposerName() |
|
562 | /** |
||
563 | * Set current composer name option value |
||
564 | * @throws \InvalidArgumentException |
||
565 | * @param string $composerName |
||
566 | 105 | * @return GeneratorOptions |
|
567 | */ |
||
568 | 105 | public function setComposerName($composerName) |
|
572 | /** |
||
573 | * Get composer settings option value |
||
574 | 60 | * @return array |
|
575 | */ |
||
576 | 60 | public function getComposerSettings() |
|
580 | /** |
||
581 | * Set current composer settings option value |
||
582 | * @throws \InvalidArgumentException |
||
583 | * @param array $composerSettings |
||
584 | 90 | * @return GeneratorOptions |
|
585 | */ |
||
586 | public function setComposerSettings(array $composerSettings = []) |
||
603 | /** |
||
604 | * turns my.key.path to array('my' => array('key' => array('path' => $value))) |
||
605 | * @param string $string |
||
606 | * @param mixed $value |
||
607 | 35 | * @param array $array |
|
608 | */ |
||
609 | 35 | protected static function dotNotationToArray($string, $value, array &$array) |
|
617 | /** |
||
618 | * Get structs folder option value |
||
619 | 375 | * @return string |
|
620 | */ |
||
621 | 375 | public function getStructsFolder() |
|
625 | /** |
||
626 | * Set current structs folder option value |
||
627 | * @throws \InvalidArgumentException |
||
628 | * @param string $structsFolder |
||
629 | 35 | * @return GeneratorOptions |
|
630 | */ |
||
631 | 35 | public function setStructsFolder($structsFolder) |
|
635 | /** |
||
636 | * Get arrays folder option value |
||
637 | 80 | * @return string |
|
638 | */ |
||
639 | 80 | public function getArraysFolder() |
|
643 | /** |
||
644 | * Set current arrays folder option value |
||
645 | * @throws \InvalidArgumentException |
||
646 | * @param string $arraysFolder |
||
647 | 35 | * @return GeneratorOptions |
|
648 | */ |
||
649 | 35 | public function setArraysFolder($arraysFolder) |
|
653 | /** |
||
654 | * Get enums folder option value |
||
655 | 150 | * @return string |
|
656 | */ |
||
657 | 150 | public function getEnumsFolder() |
|
661 | /** |
||
662 | * Set current enums folder option value |
||
663 | * @throws \InvalidArgumentException |
||
664 | * @param string $enumsFolder |
||
665 | 35 | * @return GeneratorOptions |
|
666 | */ |
||
667 | 35 | public function setEnumsFolder($enumsFolder) |
|
671 | /** |
||
672 | * Get services folder option value |
||
673 | 735 | * @return string |
|
674 | */ |
||
675 | 735 | public function getServicesFolder() |
|
679 | /** |
||
680 | * Set current services folder option value |
||
681 | * @throws \InvalidArgumentException |
||
682 | * @param string $servicesFolder |
||
683 | 35 | * @return GeneratorOptions |
|
684 | */ |
||
685 | 35 | public function setServicesFolder($servicesFolder) |
|
689 | /** |
||
690 | 45 | * Get schemas save option value |
|
691 | * @return bool |
||
692 | 45 | */ |
|
693 | 45 | public function getSchemasSave() |
|
697 | /** |
||
698 | 10 | * Set schemas save option value |
|
699 | * @throws \InvalidArgumentException |
||
700 | 10 | * |
|
701 | * @param bool $saveSchemas |
||
702 | * |
||
703 | * @return GeneratorOptions |
||
704 | */ |
||
705 | public function setSchemasSave($saveSchemas) |
||
709 | /** |
||
710 | * Get schemas folder option value |
||
711 | * @return bool |
||
712 | */ |
||
713 | public function getSchemasFolder() |
||
717 | /** |
||
718 | * Set schemas folder option value |
||
719 | * @throws \InvalidArgumentException |
||
720 | * |
||
721 | * @param string $schemasFolder |
||
722 | * |
||
723 | * @return GeneratorOptions |
||
724 | */ |
||
725 | public function setSchemasFolder($schemasFolder) |
||
729 | /** |
||
730 | * @return string[] |
||
731 | */ |
||
732 | public function toArray() |
||
744 | } |
||
745 |