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 | const XSD_TYPES_PATH = 'xsd_types_path'; |
||
52 | /** |
||
53 | * Generator's options |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $options; |
||
57 | /** |
||
58 | * @param string $filename |
||
59 | */ |
||
60 | 50 | protected function __construct($filename) |
|
65 | /** |
||
66 | * Parse options for generator |
||
67 | * @param string $filename options's file to parse |
||
68 | * @return GeneratorOptions |
||
69 | */ |
||
70 | 50 | protected function parseOptions($filename) |
|
80 | /** |
||
81 | * Returns the option value |
||
82 | * @throws \InvalidArgumentException |
||
83 | * @param string $optionName |
||
84 | * @return mixed |
||
85 | */ |
||
86 | 1510 | public function getOptionValue($optionName) |
|
93 | /** |
||
94 | * Allows to add an option and set its value |
||
95 | * @throws \InvalidArgumentException |
||
96 | * @param string $optionName |
||
97 | * @param mixed $optionValue |
||
98 | * @param array $values |
||
99 | * @return GeneratorOptions |
||
100 | */ |
||
101 | 1165 | public function setOptionValue($optionName, $optionValue, array $values = []) |
|
115 | /** |
||
116 | * @throws \InvalidArgumentException |
||
117 | * @param string $filename options's file to parse |
||
118 | * @return GeneratorOptions |
||
119 | */ |
||
120 | 1145 | public static function instance($filename = null) |
|
124 | /** |
||
125 | * @return string |
||
126 | */ |
||
127 | 470 | public static function getDefaultConfigurationPath() |
|
131 | /** |
||
132 | * Get category option value |
||
133 | * @return string |
||
134 | */ |
||
135 | 415 | public function getCategory() |
|
139 | /** |
||
140 | * Set current category option value |
||
141 | * @throws \InvalidArgumentException |
||
142 | * @param string $category |
||
143 | * @return GeneratorOptions |
||
144 | */ |
||
145 | 45 | public function setCategory($category) |
|
149 | /** |
||
150 | * Get add comments option value |
||
151 | * @return array |
||
152 | */ |
||
153 | 310 | public function getAddComments() |
|
157 | /** |
||
158 | * Set current add comments option value |
||
159 | * @throws \InvalidArgumentException |
||
160 | * @param array $addComments |
||
161 | * @return GeneratorOptions |
||
162 | */ |
||
163 | 95 | public function setAddComments(array $addComments = []) |
|
179 | /** |
||
180 | * Get gather methods option value |
||
181 | * @return string |
||
182 | */ |
||
183 | 420 | public function getGatherMethods() |
|
187 | /** |
||
188 | * Set current gather methods option value |
||
189 | * @throws \InvalidArgumentException |
||
190 | * @param string $gatherMethods |
||
191 | * @return GeneratorOptions |
||
192 | */ |
||
193 | 40 | public function setGatherMethods($gatherMethods) |
|
197 | /** |
||
198 | * Get generate tutorial file option value |
||
199 | * @return bool |
||
200 | */ |
||
201 | 50 | public function getGenerateTutorialFile() |
|
205 | /** |
||
206 | * Set current generate tutorial file option value |
||
207 | * @throws \InvalidArgumentException |
||
208 | * @param bool $generateTutorialFile |
||
209 | * @return GeneratorOptions |
||
210 | */ |
||
211 | 75 | public function setGenerateTutorialFile($generateTutorialFile) |
|
215 | /** |
||
216 | * Get namespace option value |
||
217 | * @return string |
||
218 | */ |
||
219 | 385 | public function getNamespace() |
|
223 | /** |
||
224 | * Set current namespace option value |
||
225 | * @throws \InvalidArgumentException |
||
226 | * @param string $namespace |
||
227 | * @return GeneratorOptions |
||
228 | */ |
||
229 | 55 | public function setNamespace($namespace) |
|
233 | /** |
||
234 | * Get generic constants name option value |
||
235 | * @return bool |
||
236 | */ |
||
237 | 90 | public function getGenericConstantsName() |
|
241 | /** |
||
242 | * Set current generic constants name option value |
||
243 | * @throws \InvalidArgumentException |
||
244 | * @param bool $genericConstantsName |
||
245 | * @return GeneratorOptions |
||
246 | */ |
||
247 | 75 | public function setGenericConstantsName($genericConstantsName) |
|
251 | /** |
||
252 | * Get standalone option value |
||
253 | * @return bool |
||
254 | */ |
||
255 | 95 | public function getStandalone() |
|
259 | /** |
||
260 | * Set current standalone option value |
||
261 | * @throws \InvalidArgumentException |
||
262 | * @param bool $standalone |
||
263 | * @return GeneratorOptions |
||
264 | */ |
||
265 | 45 | public function setStandalone($standalone) |
|
269 | /** |
||
270 | * Get validation option value |
||
271 | * @return bool |
||
272 | */ |
||
273 | 185 | public function getValidation() |
|
277 | /** |
||
278 | * Set current validation option value |
||
279 | * @throws \InvalidArgumentException |
||
280 | * @param bool $validation |
||
281 | * @return GeneratorOptions |
||
282 | */ |
||
283 | 40 | public function setValidation($validation) |
|
287 | /** |
||
288 | * Get struct class option value |
||
289 | * @return string |
||
290 | */ |
||
291 | 160 | public function getStructClass() |
|
295 | /** |
||
296 | * Set current struct class option value |
||
297 | * @throws \InvalidArgumentException |
||
298 | * @param string $structClass |
||
299 | * @return GeneratorOptions |
||
300 | */ |
||
301 | 45 | public function setStructClass($structClass) |
|
305 | /** |
||
306 | * Get struct array class option value |
||
307 | * @return string |
||
308 | */ |
||
309 | 60 | public function getStructArrayClass() |
|
313 | /** |
||
314 | * Set current struct array class option value |
||
315 | * @throws \InvalidArgumentException |
||
316 | * @param string $structArrayClass |
||
317 | * @return GeneratorOptions |
||
318 | */ |
||
319 | 35 | public function setStructArrayClass($structArrayClass) |
|
323 | /** |
||
324 | * Get struct array class option value |
||
325 | * @return string |
||
326 | */ |
||
327 | 135 | public function getSoapClientClass() |
|
331 | /** |
||
332 | * Set current struct array class option value |
||
333 | * @throws \InvalidArgumentException |
||
334 | * @param string $soapClientClass |
||
335 | * @return GeneratorOptions |
||
336 | */ |
||
337 | 35 | public function setSoapClientClass($soapClientClass) |
|
341 | /** |
||
342 | * Get origin option value |
||
343 | * @return string |
||
344 | */ |
||
345 | 790 | public function getOrigin() |
|
349 | /** |
||
350 | * Set current origin option value |
||
351 | * @throws \InvalidArgumentException |
||
352 | * @param string $origin |
||
353 | * @return GeneratorOptions |
||
354 | */ |
||
355 | 410 | public function setOrigin($origin) |
|
359 | /** |
||
360 | * Get destination option value |
||
361 | * @return string |
||
362 | */ |
||
363 | 445 | public function getDestination() |
|
367 | /** |
||
368 | * Set current destination option value |
||
369 | * @throws \InvalidArgumentException |
||
370 | * @param string $destination |
||
371 | * @return GeneratorOptions |
||
372 | */ |
||
373 | 415 | public function setDestination($destination) |
|
377 | /** |
||
378 | * Get src dirname option value |
||
379 | * @return string |
||
380 | */ |
||
381 | 380 | public function getSrcDirname() |
|
385 | /** |
||
386 | * Set current src dirname option value |
||
387 | * @throws \InvalidArgumentException |
||
388 | * @param string $srcDirname |
||
389 | * @return GeneratorOptions |
||
390 | */ |
||
391 | 25 | public function setSrcDirname($srcDirname) |
|
395 | /** |
||
396 | * Get prefix option value |
||
397 | * @return string |
||
398 | */ |
||
399 | 785 | public function getPrefix() |
|
403 | /** |
||
404 | * Set current prefix option value |
||
405 | * @throws \InvalidArgumentException |
||
406 | * @param string $prefix |
||
407 | * @return GeneratorOptions |
||
408 | */ |
||
409 | 135 | public function setPrefix($prefix) |
|
413 | /** |
||
414 | * Get suffix option value |
||
415 | * @return string |
||
416 | */ |
||
417 | 755 | public function getSuffix() |
|
421 | /** |
||
422 | * Set current suffix option value |
||
423 | * @throws \InvalidArgumentException |
||
424 | * @param string $suffix |
||
425 | * @return GeneratorOptions |
||
426 | */ |
||
427 | 65 | public function setSuffix($suffix) |
|
431 | /** |
||
432 | * Get basic login option value |
||
433 | * @return string |
||
434 | */ |
||
435 | 795 | public function getBasicLogin() |
|
439 | /** |
||
440 | * Set current basic login option value |
||
441 | * @throws \InvalidArgumentException |
||
442 | * @param string $basicLogin |
||
443 | * @return GeneratorOptions |
||
444 | */ |
||
445 | 35 | public function setBasicLogin($basicLogin) |
|
449 | /** |
||
450 | * Get basic password option value |
||
451 | * @return string |
||
452 | */ |
||
453 | 795 | public function getBasicPassword() |
|
457 | /** |
||
458 | * Set current basic password option value |
||
459 | * @throws \InvalidArgumentException |
||
460 | * @param string $basicPassword |
||
461 | * @return GeneratorOptions |
||
462 | */ |
||
463 | 35 | public function setBasicPassword($basicPassword) |
|
467 | /** |
||
468 | * Get basic proxy host option value |
||
469 | * @return string |
||
470 | */ |
||
471 | 795 | public function getProxyHost() |
|
475 | /** |
||
476 | * Set current proxy host option value |
||
477 | * @throws \InvalidArgumentException |
||
478 | * @param string $proxyHost |
||
479 | * @return GeneratorOptions |
||
480 | */ |
||
481 | 35 | public function setProxyHost($proxyHost) |
|
485 | /** |
||
486 | * Get basic proxy port option value |
||
487 | * @return string |
||
488 | */ |
||
489 | 795 | public function getProxyPort() |
|
493 | /** |
||
494 | * Set current proxy port option value |
||
495 | * @throws \InvalidArgumentException |
||
496 | * @param string $proxyPort |
||
497 | * @return GeneratorOptions |
||
498 | */ |
||
499 | 35 | public function setProxyPort($proxyPort) |
|
503 | /** |
||
504 | * Get basic proxy login option value |
||
505 | * @return string |
||
506 | */ |
||
507 | 795 | public function getProxyLogin() |
|
511 | /** |
||
512 | * Set current proxy login option value |
||
513 | * @throws \InvalidArgumentException |
||
514 | * @param string $proxyLogin |
||
515 | * @return GeneratorOptions |
||
516 | */ |
||
517 | 35 | public function setProxyLogin($proxyLogin) |
|
521 | /** |
||
522 | * Get basic proxy password option value |
||
523 | * @return string |
||
524 | */ |
||
525 | 795 | public function getProxyPassword() |
|
529 | /** |
||
530 | * Set current proxy password option value |
||
531 | * @throws \InvalidArgumentException |
||
532 | * @param string $proxyPassword |
||
533 | * @return GeneratorOptions |
||
534 | */ |
||
535 | 35 | public function setProxyPassword($proxyPassword) |
|
539 | /** |
||
540 | * Get basic soap options option value |
||
541 | * @return array |
||
542 | */ |
||
543 | 785 | public function getSoapOptions() |
|
547 | /** |
||
548 | * Set current soap options option value |
||
549 | * @throws \InvalidArgumentException |
||
550 | * @param array $soapOptions |
||
551 | * @return GeneratorOptions |
||
552 | */ |
||
553 | 40 | public function setSoapOptions(array $soapOptions) |
|
557 | /** |
||
558 | * Get composer name option value |
||
559 | * @return string |
||
560 | */ |
||
561 | 75 | public function getComposerName() |
|
565 | /** |
||
566 | * Set current composer name option value |
||
567 | * @throws \InvalidArgumentException |
||
568 | * @param string $composerName |
||
569 | * @return GeneratorOptions |
||
570 | */ |
||
571 | 105 | public function setComposerName($composerName) |
|
575 | /** |
||
576 | * Get composer settings option value |
||
577 | * @return array |
||
578 | */ |
||
579 | 60 | public function getComposerSettings() |
|
583 | /** |
||
584 | * Set current composer settings option value |
||
585 | * @throws \InvalidArgumentException |
||
586 | * @param array $composerSettings |
||
587 | * @return GeneratorOptions |
||
588 | */ |
||
589 | 90 | public function setComposerSettings(array $composerSettings = []) |
|
606 | /** |
||
607 | * turns my.key.path to array('my' => array('key' => array('path' => $value))) |
||
608 | * @param string $string |
||
609 | * @param mixed $value |
||
610 | * @param array $array |
||
611 | */ |
||
612 | 35 | protected static function dotNotationToArray($string, $value, array &$array) |
|
620 | /** |
||
621 | * Get structs folder option value |
||
622 | * @return string |
||
623 | */ |
||
624 | 385 | public function getStructsFolder() |
|
628 | /** |
||
629 | * Set current structs folder option value |
||
630 | * @throws \InvalidArgumentException |
||
631 | * @param string $structsFolder |
||
632 | * @return GeneratorOptions |
||
633 | */ |
||
634 | 35 | public function setStructsFolder($structsFolder) |
|
638 | /** |
||
639 | * Get arrays folder option value |
||
640 | * @return string |
||
641 | */ |
||
642 | 80 | public function getArraysFolder() |
|
646 | /** |
||
647 | * Set current arrays folder option value |
||
648 | * @throws \InvalidArgumentException |
||
649 | * @param string $arraysFolder |
||
650 | * @return GeneratorOptions |
||
651 | */ |
||
652 | 35 | public function setArraysFolder($arraysFolder) |
|
656 | /** |
||
657 | * Get enums folder option value |
||
658 | * @return string |
||
659 | */ |
||
660 | 150 | public function getEnumsFolder() |
|
664 | /** |
||
665 | * Set current enums folder option value |
||
666 | * @throws \InvalidArgumentException |
||
667 | * @param string $enumsFolder |
||
668 | * @return GeneratorOptions |
||
669 | */ |
||
670 | 35 | public function setEnumsFolder($enumsFolder) |
|
674 | /** |
||
675 | * Get services folder option value |
||
676 | * @return string |
||
677 | */ |
||
678 | 750 | public function getServicesFolder() |
|
682 | /** |
||
683 | * Set current services folder option value |
||
684 | * @throws \InvalidArgumentException |
||
685 | * @param string $servicesFolder |
||
686 | * @return GeneratorOptions |
||
687 | */ |
||
688 | 35 | public function setServicesFolder($servicesFolder) |
|
692 | /** |
||
693 | * Get schemas save option value |
||
694 | * @return bool |
||
695 | */ |
||
696 | 20 | public function getSchemasSave() |
|
700 | /** |
||
701 | * Set schemas save option value |
||
702 | * @throws \InvalidArgumentException |
||
703 | * @param bool $saveSchemas |
||
704 | * @return GeneratorOptions |
||
705 | */ |
||
706 | 40 | public function setSchemasSave($saveSchemas) |
|
710 | /** |
||
711 | * Get schemas folder option value |
||
712 | * @return string |
||
713 | */ |
||
714 | 15 | public function getSchemasFolder() |
|
718 | /** |
||
719 | * Set schemas folder option value |
||
720 | * @throws \InvalidArgumentException |
||
721 | * @param string $schemasFolder |
||
722 | * @return GeneratorOptions |
||
723 | */ |
||
724 | 40 | public function setSchemasFolder($schemasFolder) |
|
728 | /** |
||
729 | * Get xsd types path option value |
||
730 | * @return string |
||
731 | */ |
||
732 | 200 | public function getXsdTypesPath() |
|
736 | /** |
||
737 | * Set xsd types path option value |
||
738 | * @throws \InvalidArgumentException |
||
739 | * @param string $xsdTypesPath |
||
740 | * @return GeneratorOptions |
||
741 | */ |
||
742 | 5 | public function setXsdTypesPath($xsdTypesPath) |
|
746 | /** |
||
747 | * @return string[] |
||
748 | */ |
||
749 | 45 | public function toArray() |
|
761 | } |
||
762 |