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 |
||
6 | { |
||
7 | /** |
||
8 | * Common values used as option's value |
||
9 | */ |
||
10 | const VALUE_START = 'start'; |
||
11 | const VALUE_END = 'end'; |
||
12 | const VALUE_NONE = 'none'; |
||
13 | const VALUE_CAT = 'cat'; |
||
14 | const VALUE_TRUE = true; |
||
15 | const VALUE_FALSE = false; |
||
16 | /** |
||
17 | * Possible option keys |
||
18 | * @var string |
||
19 | */ |
||
20 | const SUFFIX = 'suffix'; |
||
21 | const PREFIX = 'prefix'; |
||
22 | const ORIGIN = 'origin'; |
||
23 | const CATEGORY = 'category'; |
||
24 | const VALIDATION = 'validation'; |
||
25 | const STANDALONE = 'standalone'; |
||
26 | const PROXY_HOST = 'proxy_host'; |
||
27 | const PROXY_PORT = 'proxy_port'; |
||
28 | const PROXY_LOGIN = 'proxy_login'; |
||
29 | const BASIC_LOGIN = 'basic_login'; |
||
30 | const DESTINATION = 'destination'; |
||
31 | const ADD_COMMENTS = 'add_comments'; |
||
32 | const STRUCT_CLASS = 'struct_class'; |
||
33 | const SOAP_OPTIONS = 'soap_options'; |
||
34 | const ENUMS_FOLDER = 'enums_folder'; |
||
35 | const ARRAYS_FOLDER = 'arrays_folder'; |
||
36 | const COMPOSER_NAME = 'composer_name'; |
||
37 | const STRUCTS_FOLDER = 'structs_folder'; |
||
38 | const PROXY_PASSWORD = 'proxy_password'; |
||
39 | const BASIC_PASSWORD = 'basic_password'; |
||
40 | const GATHER_METHODS = 'gather_methods'; |
||
41 | const SERVICES_FOLDER = 'services_folder'; |
||
42 | const NAMESPACE_PREFIX = 'namespace_prefix'; |
||
43 | const SOAP_CLIENT_CLASS = 'soap_client_class'; |
||
44 | const STRUCT_ARRAY_CLASS = 'struct_array_class'; |
||
45 | const GENERATE_TUTORIAL_FILE = 'generate_tutorial_file'; |
||
46 | const GENERIC_CONSTANTS_NAME = 'generic_constants_names'; |
||
47 | /** |
||
48 | * Generator's options |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $options; |
||
52 | /** |
||
53 | * @param string $filename |
||
54 | */ |
||
55 | 36 | protected function __construct($filename) |
|
60 | /** |
||
61 | * Parse options for generator |
||
62 | * @param string $filename options's file to parse |
||
63 | * @return GeneratorOptions |
||
64 | */ |
||
65 | 36 | protected function parseOptions($filename) |
|
75 | /** |
||
76 | * Returns the option value |
||
77 | * @throws InvalidArgumentException |
||
78 | * @param string $optionName |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 1032 | public function getOptionValue($optionName) |
|
88 | /** |
||
89 | * Allows to add an option and set its value |
||
90 | * @throws InvalidArgumentException |
||
91 | * @param string $optionName |
||
92 | * @return GeneratorOptions |
||
93 | */ |
||
94 | 780 | public function setOptionValue($optionName, $optionValue, array $values = array()) |
|
108 | /** |
||
109 | * @param string options's file to parse |
||
110 | * @return GeneratorOptions |
||
111 | */ |
||
112 | 764 | public static function instance($filename = null) |
|
116 | /** |
||
117 | * @return string |
||
118 | */ |
||
119 | 60 | public static function getDefaultConfigurationPath() |
|
123 | /** |
||
124 | * Get category option value |
||
125 | * @return string |
||
126 | */ |
||
127 | 268 | public function getCategory() |
|
131 | /** |
||
132 | * Set current category option value |
||
133 | * @throws \InvalidArgumentException |
||
134 | * @param string $category |
||
135 | * @return GeneratorOptions |
||
136 | */ |
||
137 | 284 | public function setCategory($category) |
|
141 | /** |
||
142 | * Get add comments option value |
||
143 | * @return array |
||
144 | */ |
||
145 | 208 | public function getAddComments() |
|
149 | /** |
||
150 | * Set current add comments option value |
||
151 | * @throws \InvalidArgumentException |
||
152 | * @param array $addComments |
||
153 | * @return GeneratorOptions |
||
154 | */ |
||
155 | 324 | public function setAddComments(array $addComments = array()) |
|
171 | /** |
||
172 | * Get gather methods option value |
||
173 | * @return string |
||
174 | */ |
||
175 | 468 | public function getGatherMethods() |
|
179 | /** |
||
180 | * Set current gather methods option value |
||
181 | * @throws \InvalidArgumentException |
||
182 | * @param string $gatherMethods |
||
183 | * @return GeneratorOptions |
||
184 | */ |
||
185 | 284 | public function setGatherMethods($gatherMethods) |
|
189 | /** |
||
190 | * Get generate tutorial file option value |
||
191 | * @return bool |
||
192 | */ |
||
193 | 36 | public function getGenerateTutorialFile() |
|
197 | /** |
||
198 | * Set current generate tutorial file option value |
||
199 | * @throws \InvalidArgumentException |
||
200 | * @param bool $generateTutorialFile |
||
201 | * @return GeneratorOptions |
||
202 | */ |
||
203 | 56 | public function setGenerateTutorialFile($generateTutorialFile) |
|
207 | /** |
||
208 | * Get namespace option value |
||
209 | * @return string |
||
210 | */ |
||
211 | 244 | public function getNamespace() |
|
215 | /** |
||
216 | * Set current namespace option value |
||
217 | * @throws \InvalidArgumentException |
||
218 | * @param string $namespace |
||
219 | * @return GeneratorOptions |
||
220 | */ |
||
221 | 36 | public function setNamespace($namespace) |
|
225 | /** |
||
226 | * Get generic constants name option value |
||
227 | * @return bool |
||
228 | */ |
||
229 | 68 | public function getGenericConstantsName() |
|
233 | /** |
||
234 | * Set current generic constants name option value |
||
235 | * @throws \InvalidArgumentException |
||
236 | * @param bool $genericConstantsName |
||
237 | * @return GeneratorOptions |
||
238 | */ |
||
239 | 56 | public function setGenericConstantsName($genericConstantsName) |
|
243 | /** |
||
244 | * Get standalone option value |
||
245 | * @return bool |
||
246 | */ |
||
247 | 68 | public function getStandalone() |
|
251 | /** |
||
252 | * Set current standalone option value |
||
253 | * @throws \InvalidArgumentException |
||
254 | * @param bool $standalone |
||
255 | * @return GeneratorOptions |
||
256 | */ |
||
257 | 32 | public function setStandalone($standalone) |
|
261 | /** |
||
262 | * Get validation option value |
||
263 | * @return bool |
||
264 | */ |
||
265 | 116 | public function getValidation() |
|
269 | /** |
||
270 | * Set current validation option value |
||
271 | * @throws \InvalidArgumentException |
||
272 | * @param bool $validation |
||
273 | * @return GeneratorOptions |
||
274 | */ |
||
275 | 12 | public function setValidation($validation) |
|
279 | /** |
||
280 | * Get struct class option value |
||
281 | * @return string |
||
282 | */ |
||
283 | 96 | public function getStructClass() |
|
287 | /** |
||
288 | * Set current struct class option value |
||
289 | * @throws \InvalidArgumentException |
||
290 | * @param string $structClass |
||
291 | * @return GeneratorOptions |
||
292 | */ |
||
293 | 36 | public function setStructClass($structClass) |
|
297 | /** |
||
298 | * Get struct array class option value |
||
299 | * @return string |
||
300 | */ |
||
301 | 44 | public function getStructArrayClass() |
|
305 | /** |
||
306 | * Set current struct array class option value |
||
307 | * @throws \InvalidArgumentException |
||
308 | * @param string $structArrayClass |
||
309 | * @return GeneratorOptions |
||
310 | */ |
||
311 | 28 | public function setStructArrayClass($structArrayClass) |
|
315 | /** |
||
316 | * Get struct array class option value |
||
317 | * @return string |
||
318 | */ |
||
319 | 96 | public function getSoapClientClass() |
|
323 | /** |
||
324 | * Set current struct array class option value |
||
325 | * @throws \InvalidArgumentException |
||
326 | * @param string $soapClientClass |
||
327 | * @return GeneratorOptions |
||
328 | */ |
||
329 | 28 | public function setSoapClientClass($soapClientClass) |
|
333 | /** |
||
334 | * Get origin option value |
||
335 | * @return string |
||
336 | */ |
||
337 | 508 | public function getOrigin() |
|
341 | /** |
||
342 | * Set current origin option value |
||
343 | * @throws \InvalidArgumentException |
||
344 | * @param string $origin |
||
345 | * @return GeneratorOptions |
||
346 | */ |
||
347 | 516 | public function setOrigin($origin) |
|
351 | /** |
||
352 | * Get destination option value |
||
353 | * @return string |
||
354 | */ |
||
355 | 284 | public function getDestination() |
|
359 | /** |
||
360 | * Set current destination option value |
||
361 | * @throws \InvalidArgumentException |
||
362 | * @param string $destination |
||
363 | * @return GeneratorOptions |
||
364 | */ |
||
365 | 520 | public function setDestination($destination) |
|
369 | /** |
||
370 | * Get prefix option value |
||
371 | * @return string |
||
372 | */ |
||
373 | 520 | public function getPrefix() |
|
377 | /** |
||
378 | * Set current prefix option value |
||
379 | * @throws \InvalidArgumentException |
||
380 | * @param string $prefix |
||
381 | * @return GeneratorOptions |
||
382 | */ |
||
383 | 300 | public function setPrefix($prefix) |
|
387 | /** |
||
388 | * Get suffix option value |
||
389 | * @return string |
||
390 | */ |
||
391 | 508 | public function getSuffix() |
|
395 | /** |
||
396 | * Set current suffix option value |
||
397 | * @throws \InvalidArgumentException |
||
398 | * @param string $suffix |
||
399 | * @return GeneratorOptions |
||
400 | */ |
||
401 | 52 | public function setSuffix($suffix) |
|
405 | /** |
||
406 | * Get basic login option value |
||
407 | * @return string |
||
408 | */ |
||
409 | 512 | public function getBasicLogin() |
|
413 | /** |
||
414 | * Set current basic login option value |
||
415 | * @throws \InvalidArgumentException |
||
416 | * @param string $basicLogin |
||
417 | * @return GeneratorOptions |
||
418 | */ |
||
419 | 28 | public function setBasicLogin($basicLogin) |
|
423 | /** |
||
424 | * Get basic password option value |
||
425 | * @return string |
||
426 | */ |
||
427 | 512 | public function getBasicPassword() |
|
431 | /** |
||
432 | * Set current basic password option value |
||
433 | * @throws \InvalidArgumentException |
||
434 | * @param string $basicPassword |
||
435 | * @return GeneratorOptions |
||
436 | */ |
||
437 | 28 | public function setBasicPassword($basicPassword) |
|
441 | /** |
||
442 | * Get basic proxy host option value |
||
443 | * @return string |
||
444 | */ |
||
445 | 512 | public function getProxyHost() |
|
449 | /** |
||
450 | * Set current proxy host option value |
||
451 | * @throws \InvalidArgumentException |
||
452 | * @param string $proxyHost |
||
453 | * @return GeneratorOptions |
||
454 | */ |
||
455 | 28 | public function setProxyHost($proxyHost) |
|
459 | /** |
||
460 | * Get basic proxy port option value |
||
461 | * @return string |
||
462 | */ |
||
463 | 512 | public function getProxyPort() |
|
467 | /** |
||
468 | * Set current proxy port option value |
||
469 | * @throws \InvalidArgumentException |
||
470 | * @param string $proxyPort |
||
471 | * @return GeneratorOptions |
||
472 | */ |
||
473 | 28 | public function setProxyPort($proxyPort) |
|
477 | /** |
||
478 | * Get basic proxy login option value |
||
479 | * @return string |
||
480 | */ |
||
481 | 512 | public function getProxyLogin() |
|
485 | /** |
||
486 | * Set current proxy login option value |
||
487 | * @throws \InvalidArgumentException |
||
488 | * @param string $proxyLogin |
||
489 | * @return GeneratorOptions |
||
490 | */ |
||
491 | 28 | public function setProxyLogin($proxyLogin) |
|
495 | /** |
||
496 | * Get basic proxy password option value |
||
497 | * @return string |
||
498 | */ |
||
499 | 512 | public function getProxyPassword() |
|
503 | /** |
||
504 | * Set current proxy password option value |
||
505 | * @throws \InvalidArgumentException |
||
506 | * @param string $proxyPassword |
||
507 | * @return GeneratorOptions |
||
508 | */ |
||
509 | 28 | public function setProxyPassword($proxyPassword) |
|
513 | /** |
||
514 | * Get basic soap options option value |
||
515 | * @return array |
||
516 | */ |
||
517 | 504 | public function getSoapOptions() |
|
521 | /** |
||
522 | * Set current soap options option value |
||
523 | * @throws \InvalidArgumentException |
||
524 | * @param array $soapOptions |
||
525 | * @return GeneratorOptions |
||
526 | */ |
||
527 | 32 | public function setSoapOptions(array $soapOptions) |
|
531 | /** |
||
532 | * Get composer name option value |
||
533 | * @return string |
||
534 | */ |
||
535 | 44 | public function getComposerName() |
|
539 | /** |
||
540 | * Set current composer name option value |
||
541 | * @throws \InvalidArgumentException |
||
542 | * @param string $composerName |
||
543 | * @return GeneratorOptions |
||
544 | */ |
||
545 | 68 | public function setComposerName($composerName) |
|
549 | /** |
||
550 | * Get structs folder option value |
||
551 | * @return string |
||
552 | */ |
||
553 | 252 | public function getStructsFolder() |
|
557 | /** |
||
558 | * Set current structs folder option value |
||
559 | * @throws \InvalidArgumentException |
||
560 | * @param string $structsFolder |
||
561 | * @return GeneratorOptions |
||
562 | */ |
||
563 | 28 | public function setStructsFolder($structsFolder) |
|
567 | /** |
||
568 | * Get arrays folder option value |
||
569 | * @return string |
||
570 | */ |
||
571 | 60 | public function getArraysFolder() |
|
575 | /** |
||
576 | * Set current arrays folder option value |
||
577 | * @throws \InvalidArgumentException |
||
578 | * @param string $arraysFolder |
||
579 | * @return GeneratorOptions |
||
580 | */ |
||
581 | 28 | public function setArraysFolder($arraysFolder) |
|
585 | /** |
||
586 | * Get enums folder option value |
||
587 | * @return string |
||
588 | */ |
||
589 | 100 | public function getEnumsFolder() |
|
593 | /** |
||
594 | * Set current enums folder option value |
||
595 | * @throws \InvalidArgumentException |
||
596 | * @param string $enumsFolder |
||
597 | * @return GeneratorOptions |
||
598 | */ |
||
599 | 28 | public function setEnumsFolder($enumsFolder) |
|
603 | /** |
||
604 | * Get services folder option value |
||
605 | * @return string |
||
606 | */ |
||
607 | 500 | public function getServicesFolder() |
|
611 | /** |
||
612 | * Set current services folder option value |
||
613 | * @throws \InvalidArgumentException |
||
614 | * @param string $servicesFolder |
||
615 | * @return GeneratorOptions |
||
616 | */ |
||
617 | 28 | public function setServicesFolder($servicesFolder) |
|
621 | /** |
||
622 | * @return string[] |
||
623 | */ |
||
624 | 28 | public function toArray() |
|
632 | } |
||
633 |