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 | /** |
||
50 | * Generator's options |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $options; |
||
54 | /** |
||
55 | * @param string $filename |
||
56 | */ |
||
57 | protected function __construct($filename) |
||
62 | /** |
||
63 | * Parse options for generator |
||
64 | * @param string $filename options's file to parse |
||
65 | * @return GeneratorOptions |
||
66 | */ |
||
67 | protected function parseOptions($filename) |
||
77 | /** |
||
78 | * Returns the option value |
||
79 | * @throws \InvalidArgumentException |
||
80 | * @param string $optionName |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function getOptionValue($optionName) |
||
90 | /** |
||
91 | * Allows to add an option and set its value |
||
92 | * @throws \InvalidArgumentException |
||
93 | * @param string $optionName |
||
94 | * @return GeneratorOptions |
||
95 | */ |
||
96 | public function setOptionValue($optionName, $optionValue, array $values = array()) |
||
110 | /** |
||
111 | * @throws \InvalidArgumentException |
||
112 | * @param string $filename options's file to parse |
||
113 | * @return GeneratorOptions |
||
114 | */ |
||
115 | public static function instance($filename = null) |
||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | public static function getDefaultConfigurationPath() |
||
126 | /** |
||
127 | * Get category option value |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getCategory() |
||
134 | /** |
||
135 | * Set current category option value |
||
136 | * @throws \InvalidArgumentException |
||
137 | * @param string $category |
||
138 | * @return GeneratorOptions |
||
139 | */ |
||
140 | public function setCategory($category) |
||
144 | /** |
||
145 | * Get add comments option value |
||
146 | * @return array |
||
147 | */ |
||
148 | public function getAddComments() |
||
152 | /** |
||
153 | * Set current add comments option value |
||
154 | * @throws \InvalidArgumentException |
||
155 | * @param array $addComments |
||
156 | * @return GeneratorOptions |
||
157 | */ |
||
158 | public function setAddComments(array $addComments = array()) |
||
174 | /** |
||
175 | * Get gather methods option value |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getGatherMethods() |
||
182 | /** |
||
183 | * Set current gather methods option value |
||
184 | * @throws \InvalidArgumentException |
||
185 | * @param string $gatherMethods |
||
186 | * @return GeneratorOptions |
||
187 | */ |
||
188 | public function setGatherMethods($gatherMethods) |
||
192 | /** |
||
193 | * Get generate tutorial file option value |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function getGenerateTutorialFile() |
||
200 | /** |
||
201 | * Set current generate tutorial file option value |
||
202 | * @throws \InvalidArgumentException |
||
203 | * @param bool $generateTutorialFile |
||
204 | * @return GeneratorOptions |
||
205 | */ |
||
206 | public function setGenerateTutorialFile($generateTutorialFile) |
||
210 | /** |
||
211 | * Get namespace option value |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getNamespace() |
||
218 | /** |
||
219 | * Set current namespace option value |
||
220 | * @throws \InvalidArgumentException |
||
221 | * @param string $namespace |
||
222 | * @return GeneratorOptions |
||
223 | */ |
||
224 | public function setNamespace($namespace) |
||
228 | /** |
||
229 | * Get generic constants name option value |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function getGenericConstantsName() |
||
236 | /** |
||
237 | * Set current generic constants name option value |
||
238 | * @throws \InvalidArgumentException |
||
239 | * @param bool $genericConstantsName |
||
240 | * @return GeneratorOptions |
||
241 | */ |
||
242 | public function setGenericConstantsName($genericConstantsName) |
||
246 | /** |
||
247 | * Get standalone option value |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function getStandalone() |
||
254 | /** |
||
255 | * Set current standalone option value |
||
256 | * @throws \InvalidArgumentException |
||
257 | * @param bool $standalone |
||
258 | * @return GeneratorOptions |
||
259 | */ |
||
260 | public function setStandalone($standalone) |
||
264 | /** |
||
265 | * Get validation option value |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function getValidation() |
||
272 | /** |
||
273 | * Set current validation option value |
||
274 | * @throws \InvalidArgumentException |
||
275 | * @param bool $validation |
||
276 | * @return GeneratorOptions |
||
277 | */ |
||
278 | public function setValidation($validation) |
||
282 | /** |
||
283 | * Get struct class option value |
||
284 | * @return string |
||
285 | */ |
||
286 | public function getStructClass() |
||
290 | /** |
||
291 | * Set current struct class option value |
||
292 | * @throws \InvalidArgumentException |
||
293 | * @param string $structClass |
||
294 | * @return GeneratorOptions |
||
295 | */ |
||
296 | public function setStructClass($structClass) |
||
300 | /** |
||
301 | * Get struct array class option value |
||
302 | * @return string |
||
303 | */ |
||
304 | public function getStructArrayClass() |
||
308 | /** |
||
309 | * Set current struct array class option value |
||
310 | * @throws \InvalidArgumentException |
||
311 | * @param string $structArrayClass |
||
312 | * @return GeneratorOptions |
||
313 | */ |
||
314 | public function setStructArrayClass($structArrayClass) |
||
318 | /** |
||
319 | * Get struct array class option value |
||
320 | * @return string |
||
321 | */ |
||
322 | public function getSoapClientClass() |
||
326 | /** |
||
327 | * Set current struct array class option value |
||
328 | * @throws \InvalidArgumentException |
||
329 | * @param string $soapClientClass |
||
330 | * @return GeneratorOptions |
||
331 | */ |
||
332 | public function setSoapClientClass($soapClientClass) |
||
336 | /** |
||
337 | * Get origin option value |
||
338 | * @return string |
||
339 | */ |
||
340 | public function getOrigin() |
||
344 | /** |
||
345 | * Set current origin option value |
||
346 | * @throws \InvalidArgumentException |
||
347 | * @param string $origin |
||
348 | * @return GeneratorOptions |
||
349 | */ |
||
350 | public function setOrigin($origin) |
||
354 | /** |
||
355 | * Get destination option value |
||
356 | * @return string |
||
357 | */ |
||
358 | public function getDestination() |
||
362 | /** |
||
363 | * Set current destination option value |
||
364 | * @throws \InvalidArgumentException |
||
365 | * @param string $destination |
||
366 | * @return GeneratorOptions |
||
367 | */ |
||
368 | public function setDestination($destination) |
||
372 | /** |
||
373 | * Get src dirname option value |
||
374 | * @return string |
||
375 | */ |
||
376 | public function getSrcDirname() |
||
380 | /** |
||
381 | * Set current src dirname option value |
||
382 | * @throws \InvalidArgumentException |
||
383 | * @param string $srcDirname |
||
384 | * @return GeneratorOptions |
||
385 | */ |
||
386 | public function setSrcDirname($srcDirname) |
||
390 | /** |
||
391 | * Get prefix option value |
||
392 | * @return string |
||
393 | */ |
||
394 | public function getPrefix() |
||
398 | /** |
||
399 | * Set current prefix option value |
||
400 | * @throws \InvalidArgumentException |
||
401 | * @param string $prefix |
||
402 | * @return GeneratorOptions |
||
403 | */ |
||
404 | public function setPrefix($prefix) |
||
408 | /** |
||
409 | * Get suffix option value |
||
410 | * @return string |
||
411 | */ |
||
412 | public function getSuffix() |
||
416 | /** |
||
417 | * Set current suffix option value |
||
418 | * @throws \InvalidArgumentException |
||
419 | * @param string $suffix |
||
420 | * @return GeneratorOptions |
||
421 | */ |
||
422 | public function setSuffix($suffix) |
||
426 | /** |
||
427 | * Get basic login option value |
||
428 | * @return string |
||
429 | */ |
||
430 | public function getBasicLogin() |
||
434 | /** |
||
435 | * Set current basic login option value |
||
436 | * @throws \InvalidArgumentException |
||
437 | * @param string $basicLogin |
||
438 | * @return GeneratorOptions |
||
439 | */ |
||
440 | public function setBasicLogin($basicLogin) |
||
444 | /** |
||
445 | * Get basic password option value |
||
446 | * @return string |
||
447 | */ |
||
448 | public function getBasicPassword() |
||
452 | /** |
||
453 | * Set current basic password option value |
||
454 | * @throws \InvalidArgumentException |
||
455 | * @param string $basicPassword |
||
456 | * @return GeneratorOptions |
||
457 | */ |
||
458 | public function setBasicPassword($basicPassword) |
||
462 | /** |
||
463 | * Get basic proxy host option value |
||
464 | * @return string |
||
465 | */ |
||
466 | public function getProxyHost() |
||
470 | /** |
||
471 | * Set current proxy host option value |
||
472 | * @throws \InvalidArgumentException |
||
473 | * @param string $proxyHost |
||
474 | * @return GeneratorOptions |
||
475 | */ |
||
476 | public function setProxyHost($proxyHost) |
||
480 | /** |
||
481 | * Get basic proxy port option value |
||
482 | * @return string |
||
483 | */ |
||
484 | public function getProxyPort() |
||
488 | /** |
||
489 | * Set current proxy port option value |
||
490 | * @throws \InvalidArgumentException |
||
491 | * @param string $proxyPort |
||
492 | * @return GeneratorOptions |
||
493 | */ |
||
494 | public function setProxyPort($proxyPort) |
||
498 | /** |
||
499 | * Get basic proxy login option value |
||
500 | * @return string |
||
501 | */ |
||
502 | public function getProxyLogin() |
||
506 | /** |
||
507 | * Set current proxy login option value |
||
508 | * @throws \InvalidArgumentException |
||
509 | * @param string $proxyLogin |
||
510 | * @return GeneratorOptions |
||
511 | */ |
||
512 | public function setProxyLogin($proxyLogin) |
||
516 | /** |
||
517 | * Get basic proxy password option value |
||
518 | * @return string |
||
519 | */ |
||
520 | public function getProxyPassword() |
||
524 | /** |
||
525 | * Set current proxy password option value |
||
526 | * @throws \InvalidArgumentException |
||
527 | * @param string $proxyPassword |
||
528 | * @return GeneratorOptions |
||
529 | */ |
||
530 | public function setProxyPassword($proxyPassword) |
||
534 | /** |
||
535 | * Get basic soap options option value |
||
536 | * @return array |
||
537 | */ |
||
538 | public function getSoapOptions() |
||
542 | /** |
||
543 | * Set current soap options option value |
||
544 | * @throws \InvalidArgumentException |
||
545 | * @param array $soapOptions |
||
546 | * @return GeneratorOptions |
||
547 | */ |
||
548 | public function setSoapOptions(array $soapOptions) |
||
552 | /** |
||
553 | * Get composer name option value |
||
554 | * @return string |
||
555 | */ |
||
556 | public function getComposerName() |
||
560 | /** |
||
561 | * Set current composer name option value |
||
562 | * @throws \InvalidArgumentException |
||
563 | * @param string $composerName |
||
564 | * @return GeneratorOptions |
||
565 | */ |
||
566 | public function setComposerName($composerName) |
||
570 | /** |
||
571 | * Get composer settings option value |
||
572 | * @return array |
||
573 | */ |
||
574 | public function getComposerSettings() |
||
578 | /** |
||
579 | * Set current composer settings option value |
||
580 | * @throws \InvalidArgumentException |
||
581 | * @param array $composerSettings |
||
582 | * @return GeneratorOptions |
||
583 | */ |
||
584 | public function setComposerSettings(array $composerSettings = array()) |
||
601 | /** |
||
602 | * turns my.key.path to array('my' => array('key' => array('path' => $value))) |
||
603 | * @param string $string |
||
604 | * @param mixed $value |
||
605 | * @param array $array |
||
606 | */ |
||
607 | protected static function dotNotationToArray($string, $value, array &$array) |
||
615 | /** |
||
616 | * Get structs folder option value |
||
617 | * @return string |
||
618 | */ |
||
619 | public function getStructsFolder() |
||
623 | /** |
||
624 | * Set current structs folder option value |
||
625 | * @throws \InvalidArgumentException |
||
626 | * @param string $structsFolder |
||
627 | * @return GeneratorOptions |
||
628 | */ |
||
629 | public function setStructsFolder($structsFolder) |
||
633 | /** |
||
634 | * Get arrays folder option value |
||
635 | * @return string |
||
636 | */ |
||
637 | public function getArraysFolder() |
||
641 | /** |
||
642 | * Set current arrays folder option value |
||
643 | * @throws \InvalidArgumentException |
||
644 | * @param string $arraysFolder |
||
645 | * @return GeneratorOptions |
||
646 | */ |
||
647 | public function setArraysFolder($arraysFolder) |
||
651 | /** |
||
652 | * Get enums folder option value |
||
653 | * @return string |
||
654 | */ |
||
655 | public function getEnumsFolder() |
||
659 | /** |
||
660 | * Set current enums folder option value |
||
661 | * @throws \InvalidArgumentException |
||
662 | * @param string $enumsFolder |
||
663 | * @return GeneratorOptions |
||
664 | */ |
||
665 | public function setEnumsFolder($enumsFolder) |
||
669 | /** |
||
670 | * Get services folder option value |
||
671 | * @return string |
||
672 | */ |
||
673 | public function getServicesFolder() |
||
677 | /** |
||
678 | * Set current services folder option value |
||
679 | * @throws \InvalidArgumentException |
||
680 | * @param string $servicesFolder |
||
681 | * @return GeneratorOptions |
||
682 | */ |
||
683 | public function setServicesFolder($servicesFolder) |
||
687 | /** |
||
688 | * @return string[] |
||
689 | */ |
||
690 | public function toArray() |
||
702 | } |
||
703 |