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_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 STANDALONE = 'standalone'; |
||
| 43 | const STRUCT_ARRAY_CLASS = 'struct_array_class'; |
||
| 44 | const STRUCT_CLASS = 'struct_class'; |
||
| 45 | const STRUCTS_FOLDER = 'structs_folder'; |
||
| 46 | const SUFFIX = 'suffix'; |
||
| 47 | const VALIDATION = 'validation'; |
||
| 48 | /** |
||
| 49 | * Generator's options |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | protected $options; |
||
| 53 | /** |
||
| 54 | * @param string $filename |
||
| 55 | */ |
||
| 56 | 36 | protected function __construct($filename) |
|
| 61 | /** |
||
| 62 | * Parse options for generator |
||
| 63 | * @param string $filename options's file to parse |
||
| 64 | * @return GeneratorOptions |
||
| 65 | */ |
||
| 66 | 36 | protected function parseOptions($filename) |
|
| 76 | /** |
||
| 77 | * Returns the option value |
||
| 78 | * @throws \InvalidArgumentException |
||
| 79 | * @param string $optionName |
||
| 80 | * @return mixed |
||
| 81 | */ |
||
| 82 | 1068 | public function getOptionValue($optionName) |
|
| 89 | /** |
||
| 90 | * Allows to add an option and set its value |
||
| 91 | * @throws \InvalidArgumentException |
||
| 92 | * @param string $optionName |
||
| 93 | * @return GeneratorOptions |
||
| 94 | */ |
||
| 95 | 808 | public function setOptionValue($optionName, $optionValue, array $values = array()) |
|
| 109 | /** |
||
| 110 | * @throws \InvalidArgumentException |
||
| 111 | * @param string $filename options's file to parse |
||
| 112 | * @return GeneratorOptions |
||
| 113 | */ |
||
| 114 | 788 | public static function instance($filename = null) |
|
| 118 | /** |
||
| 119 | * @return string |
||
| 120 | */ |
||
| 121 | 60 | public static function getDefaultConfigurationPath() |
|
| 125 | /** |
||
| 126 | * Get category option value |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | 288 | public function getCategory() |
|
| 133 | /** |
||
| 134 | * Set current category option value |
||
| 135 | * @throws \InvalidArgumentException |
||
| 136 | * @param string $category |
||
| 137 | * @return GeneratorOptions |
||
| 138 | */ |
||
| 139 | 300 | public function setCategory($category) |
|
| 143 | /** |
||
| 144 | * Get add comments option value |
||
| 145 | * @return array |
||
| 146 | */ |
||
| 147 | 216 | public function getAddComments() |
|
| 151 | /** |
||
| 152 | * Set current add comments option value |
||
| 153 | * @throws \InvalidArgumentException |
||
| 154 | * @param array $addComments |
||
| 155 | * @return GeneratorOptions |
||
| 156 | */ |
||
| 157 | 340 | public function setAddComments(array $addComments = array()) |
|
| 173 | /** |
||
| 174 | * Get gather methods option value |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | 484 | public function getGatherMethods() |
|
| 181 | /** |
||
| 182 | * Set current gather methods option value |
||
| 183 | * @throws \InvalidArgumentException |
||
| 184 | * @param string $gatherMethods |
||
| 185 | * @return GeneratorOptions |
||
| 186 | */ |
||
| 187 | 300 | public function setGatherMethods($gatherMethods) |
|
| 191 | /** |
||
| 192 | * Get generate tutorial file option value |
||
| 193 | * @return bool |
||
| 194 | */ |
||
| 195 | 36 | public function getGenerateTutorialFile() |
|
| 199 | /** |
||
| 200 | * Set current generate tutorial file option value |
||
| 201 | * @throws \InvalidArgumentException |
||
| 202 | * @param bool $generateTutorialFile |
||
| 203 | * @return GeneratorOptions |
||
| 204 | */ |
||
| 205 | 56 | public function setGenerateTutorialFile($generateTutorialFile) |
|
| 209 | /** |
||
| 210 | * Get namespace option value |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | 264 | public function getNamespace() |
|
| 217 | /** |
||
| 218 | * Set current namespace option value |
||
| 219 | * @throws \InvalidArgumentException |
||
| 220 | * @param string $namespace |
||
| 221 | * @return GeneratorOptions |
||
| 222 | */ |
||
| 223 | 44 | public function setNamespace($namespace) |
|
| 227 | /** |
||
| 228 | * Get generic constants name option value |
||
| 229 | * @return bool |
||
| 230 | */ |
||
| 231 | 68 | public function getGenericConstantsName() |
|
| 235 | /** |
||
| 236 | * Set current generic constants name option value |
||
| 237 | * @throws \InvalidArgumentException |
||
| 238 | * @param bool $genericConstantsName |
||
| 239 | * @return GeneratorOptions |
||
| 240 | */ |
||
| 241 | 56 | public function setGenericConstantsName($genericConstantsName) |
|
| 245 | /** |
||
| 246 | * Get standalone option value |
||
| 247 | * @return bool |
||
| 248 | */ |
||
| 249 | 68 | public function getStandalone() |
|
| 253 | /** |
||
| 254 | * Set current standalone option value |
||
| 255 | * @throws \InvalidArgumentException |
||
| 256 | * @param bool $standalone |
||
| 257 | * @return GeneratorOptions |
||
| 258 | */ |
||
| 259 | 32 | public function setStandalone($standalone) |
|
| 263 | /** |
||
| 264 | * Get validation option value |
||
| 265 | * @return bool |
||
| 266 | */ |
||
| 267 | 120 | public function getValidation() |
|
| 271 | /** |
||
| 272 | * Set current validation option value |
||
| 273 | * @throws \InvalidArgumentException |
||
| 274 | * @param bool $validation |
||
| 275 | * @return GeneratorOptions |
||
| 276 | */ |
||
| 277 | 16 | public function setValidation($validation) |
|
| 281 | /** |
||
| 282 | * Get struct class option value |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | 100 | public function getStructClass() |
|
| 289 | /** |
||
| 290 | * Set current struct class option value |
||
| 291 | * @throws \InvalidArgumentException |
||
| 292 | * @param string $structClass |
||
| 293 | * @return GeneratorOptions |
||
| 294 | */ |
||
| 295 | 36 | public function setStructClass($structClass) |
|
| 299 | /** |
||
| 300 | * Get struct array class option value |
||
| 301 | * @return string |
||
| 302 | */ |
||
| 303 | 44 | public function getStructArrayClass() |
|
| 307 | /** |
||
| 308 | * Set current struct array class option value |
||
| 309 | * @throws \InvalidArgumentException |
||
| 310 | * @param string $structArrayClass |
||
| 311 | * @return GeneratorOptions |
||
| 312 | */ |
||
| 313 | 28 | public function setStructArrayClass($structArrayClass) |
|
| 317 | /** |
||
| 318 | * Get struct array class option value |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | 100 | public function getSoapClientClass() |
|
| 325 | /** |
||
| 326 | * Set current struct array class option value |
||
| 327 | * @throws \InvalidArgumentException |
||
| 328 | * @param string $soapClientClass |
||
| 329 | * @return GeneratorOptions |
||
| 330 | */ |
||
| 331 | 28 | public function setSoapClientClass($soapClientClass) |
|
| 335 | /** |
||
| 336 | * Get origin option value |
||
| 337 | * @return string |
||
| 338 | */ |
||
| 339 | 524 | public function getOrigin() |
|
| 343 | /** |
||
| 344 | * Set current origin option value |
||
| 345 | * @throws \InvalidArgumentException |
||
| 346 | * @param string $origin |
||
| 347 | * @return GeneratorOptions |
||
| 348 | */ |
||
| 349 | 532 | public function setOrigin($origin) |
|
| 353 | /** |
||
| 354 | * Get destination option value |
||
| 355 | * @return string |
||
| 356 | */ |
||
| 357 | 304 | public function getDestination() |
|
| 361 | /** |
||
| 362 | * Set current destination option value |
||
| 363 | * @throws \InvalidArgumentException |
||
| 364 | * @param string $destination |
||
| 365 | * @return GeneratorOptions |
||
| 366 | */ |
||
| 367 | 536 | public function setDestination($destination) |
|
| 371 | /** |
||
| 372 | * Get prefix option value |
||
| 373 | * @return string |
||
| 374 | */ |
||
| 375 | 544 | public function getPrefix() |
|
| 379 | /** |
||
| 380 | * Set current prefix option value |
||
| 381 | * @throws \InvalidArgumentException |
||
| 382 | * @param string $prefix |
||
| 383 | * @return GeneratorOptions |
||
| 384 | */ |
||
| 385 | 320 | public function setPrefix($prefix) |
|
| 389 | /** |
||
| 390 | * Get suffix option value |
||
| 391 | * @return string |
||
| 392 | */ |
||
| 393 | 528 | public function getSuffix() |
|
| 397 | /** |
||
| 398 | * Set current suffix option value |
||
| 399 | * @throws \InvalidArgumentException |
||
| 400 | * @param string $suffix |
||
| 401 | * @return GeneratorOptions |
||
| 402 | */ |
||
| 403 | 52 | public function setSuffix($suffix) |
|
| 407 | /** |
||
| 408 | * Get basic login option value |
||
| 409 | * @return string |
||
| 410 | */ |
||
| 411 | 528 | public function getBasicLogin() |
|
| 415 | /** |
||
| 416 | * Set current basic login option value |
||
| 417 | * @throws \InvalidArgumentException |
||
| 418 | * @param string $basicLogin |
||
| 419 | * @return GeneratorOptions |
||
| 420 | */ |
||
| 421 | 28 | public function setBasicLogin($basicLogin) |
|
| 425 | /** |
||
| 426 | * Get basic password option value |
||
| 427 | * @return string |
||
| 428 | */ |
||
| 429 | 528 | public function getBasicPassword() |
|
| 433 | /** |
||
| 434 | * Set current basic password option value |
||
| 435 | * @throws \InvalidArgumentException |
||
| 436 | * @param string $basicPassword |
||
| 437 | * @return GeneratorOptions |
||
| 438 | */ |
||
| 439 | 28 | public function setBasicPassword($basicPassword) |
|
| 443 | /** |
||
| 444 | * Get basic proxy host option value |
||
| 445 | * @return string |
||
| 446 | */ |
||
| 447 | 528 | public function getProxyHost() |
|
| 451 | /** |
||
| 452 | * Set current proxy host option value |
||
| 453 | * @throws \InvalidArgumentException |
||
| 454 | * @param string $proxyHost |
||
| 455 | * @return GeneratorOptions |
||
| 456 | */ |
||
| 457 | 28 | public function setProxyHost($proxyHost) |
|
| 461 | /** |
||
| 462 | * Get basic proxy port option value |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | 528 | public function getProxyPort() |
|
| 469 | /** |
||
| 470 | * Set current proxy port option value |
||
| 471 | * @throws \InvalidArgumentException |
||
| 472 | * @param string $proxyPort |
||
| 473 | * @return GeneratorOptions |
||
| 474 | */ |
||
| 475 | 28 | public function setProxyPort($proxyPort) |
|
| 479 | /** |
||
| 480 | * Get basic proxy login option value |
||
| 481 | * @return string |
||
| 482 | */ |
||
| 483 | 528 | public function getProxyLogin() |
|
| 487 | /** |
||
| 488 | * Set current proxy login option value |
||
| 489 | * @throws \InvalidArgumentException |
||
| 490 | * @param string $proxyLogin |
||
| 491 | * @return GeneratorOptions |
||
| 492 | */ |
||
| 493 | 28 | public function setProxyLogin($proxyLogin) |
|
| 497 | /** |
||
| 498 | * Get basic proxy password option value |
||
| 499 | * @return string |
||
| 500 | */ |
||
| 501 | 528 | public function getProxyPassword() |
|
| 505 | /** |
||
| 506 | * Set current proxy password option value |
||
| 507 | * @throws \InvalidArgumentException |
||
| 508 | * @param string $proxyPassword |
||
| 509 | * @return GeneratorOptions |
||
| 510 | */ |
||
| 511 | 28 | public function setProxyPassword($proxyPassword) |
|
| 515 | /** |
||
| 516 | * Get basic soap options option value |
||
| 517 | * @return array |
||
| 518 | */ |
||
| 519 | 520 | public function getSoapOptions() |
|
| 523 | /** |
||
| 524 | * Set current soap options option value |
||
| 525 | * @throws \InvalidArgumentException |
||
| 526 | * @param array $soapOptions |
||
| 527 | * @return GeneratorOptions |
||
| 528 | */ |
||
| 529 | 32 | public function setSoapOptions(array $soapOptions) |
|
| 533 | /** |
||
| 534 | * Get composer name option value |
||
| 535 | * @return string |
||
| 536 | */ |
||
| 537 | 48 | public function getComposerName() |
|
| 541 | /** |
||
| 542 | * Set current composer name option value |
||
| 543 | * @throws \InvalidArgumentException |
||
| 544 | * @param string $composerName |
||
| 545 | * @return GeneratorOptions |
||
| 546 | */ |
||
| 547 | 72 | public function setComposerName($composerName) |
|
| 551 | /** |
||
| 552 | * Get composer settings option value |
||
| 553 | * @return array |
||
| 554 | */ |
||
| 555 | 36 | public function getComposerSettings() |
|
| 559 | /** |
||
| 560 | * Set current composer settings option value |
||
| 561 | * @throws \InvalidArgumentException |
||
| 562 | * @param array $composerSettings |
||
| 563 | * @return GeneratorOptions |
||
| 564 | */ |
||
| 565 | 68 | public function setComposerSettings(array $composerSettings = array()) |
|
| 582 | /** |
||
| 583 | * turns my.key.path to array('my' => array('key' => array('path' => $value))) |
||
| 584 | * @param string $string |
||
| 585 | * @param mixed $value |
||
| 586 | * @param array $array |
||
| 587 | */ |
||
| 588 | 28 | protected static function dotNotationToArray($string, $value, array &$array) |
|
| 596 | /** |
||
| 597 | * Get structs folder option value |
||
| 598 | * @return string |
||
| 599 | */ |
||
| 600 | 268 | public function getStructsFolder() |
|
| 604 | /** |
||
| 605 | * Set current structs folder option value |
||
| 606 | * @throws \InvalidArgumentException |
||
| 607 | * @param string $structsFolder |
||
| 608 | * @return GeneratorOptions |
||
| 609 | */ |
||
| 610 | 28 | public function setStructsFolder($structsFolder) |
|
| 614 | /** |
||
| 615 | * Get arrays folder option value |
||
| 616 | * @return string |
||
| 617 | */ |
||
| 618 | 60 | public function getArraysFolder() |
|
| 622 | /** |
||
| 623 | * Set current arrays folder option value |
||
| 624 | * @throws \InvalidArgumentException |
||
| 625 | * @param string $arraysFolder |
||
| 626 | * @return GeneratorOptions |
||
| 627 | */ |
||
| 628 | 28 | public function setArraysFolder($arraysFolder) |
|
| 632 | /** |
||
| 633 | * Get enums folder option value |
||
| 634 | * @return string |
||
| 635 | */ |
||
| 636 | 100 | public function getEnumsFolder() |
|
| 640 | /** |
||
| 641 | * Set current enums folder option value |
||
| 642 | * @throws \InvalidArgumentException |
||
| 643 | * @param string $enumsFolder |
||
| 644 | * @return GeneratorOptions |
||
| 645 | */ |
||
| 646 | 28 | public function setEnumsFolder($enumsFolder) |
|
| 650 | /** |
||
| 651 | * Get services folder option value |
||
| 652 | * @return string |
||
| 653 | */ |
||
| 654 | 520 | public function getServicesFolder() |
|
| 658 | /** |
||
| 659 | * Set current services folder option value |
||
| 660 | * @throws \InvalidArgumentException |
||
| 661 | * @param string $servicesFolder |
||
| 662 | * @return GeneratorOptions |
||
| 663 | */ |
||
| 664 | 28 | public function setServicesFolder($servicesFolder) |
|
| 668 | /** |
||
| 669 | * @return string[] |
||
| 670 | */ |
||
| 671 | 28 | public function toArray() |
|
| 679 | } |
||
| 680 |