Complex classes like Generator 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 Generator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Generator |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Wsdl |
||
| 21 | * @var Wsdl |
||
| 22 | */ |
||
| 23 | private $wsdl; |
||
| 24 | /** |
||
| 25 | * @var GeneratorOptions |
||
| 26 | */ |
||
| 27 | private $options; |
||
| 28 | /** |
||
| 29 | * Used parsers |
||
| 30 | * @var GeneratorParsers |
||
| 31 | */ |
||
| 32 | private $parsers; |
||
| 33 | /** |
||
| 34 | * Used files |
||
| 35 | * @var GeneratorFiles |
||
| 36 | */ |
||
| 37 | private $files; |
||
| 38 | /** |
||
| 39 | * Used containers |
||
| 40 | * @var GeneratorContainers |
||
| 41 | */ |
||
| 42 | private $containers; |
||
| 43 | /** |
||
| 44 | * Used SoapClient |
||
| 45 | * @var GeneratorSoapClient |
||
| 46 | */ |
||
| 47 | private $soapClient; |
||
| 48 | /** |
||
| 49 | * Constructor |
||
| 50 | * @param GeneratorOptions $options |
||
| 51 | */ |
||
| 52 | 504 | public function __construct(GeneratorOptions $options) |
|
| 56 | /** |
||
| 57 | * @return Generator |
||
| 58 | */ |
||
| 59 | 504 | protected function initialize() |
|
| 67 | /** |
||
| 68 | * @throws \InvalidArgumentException |
||
| 69 | * @return Generator |
||
| 70 | */ |
||
| 71 | 504 | protected function initSoapClient() |
|
| 78 | /** |
||
| 79 | * @return Generator |
||
| 80 | */ |
||
| 81 | 504 | protected function initContainers() |
|
| 88 | /** |
||
| 89 | * @return Generator |
||
| 90 | */ |
||
| 91 | 504 | protected function initParsers() |
|
| 98 | /** |
||
| 99 | * @return GeneratorParsers |
||
| 100 | */ |
||
| 101 | 180 | public function getParsers() |
|
| 105 | /** |
||
| 106 | * @return Generator |
||
| 107 | */ |
||
| 108 | 504 | protected function initFiles() |
|
| 115 | /** |
||
| 116 | * @return GeneratorFiles |
||
| 117 | */ |
||
| 118 | 44 | public function getFiles() |
|
| 122 | /** |
||
| 123 | * @throws \InvalidArgumentException |
||
| 124 | * @return Generator |
||
| 125 | */ |
||
| 126 | 24 | protected function initDirectory() |
|
| 134 | /** |
||
| 135 | * @return Generator |
||
| 136 | */ |
||
| 137 | 504 | protected function initWsdl() |
|
| 142 | /** |
||
| 143 | * @return Generator |
||
| 144 | */ |
||
| 145 | 32 | protected function doSanityChecks() |
|
| 157 | /** |
||
| 158 | * @return Generator |
||
| 159 | */ |
||
| 160 | 20 | protected function doParse() |
|
| 165 | /** |
||
| 166 | * @return Generator |
||
| 167 | */ |
||
| 168 | 20 | protected function doGenerate() |
|
| 173 | /** |
||
| 174 | * Generates all classes based on options |
||
| 175 | * @return Generator |
||
| 176 | */ |
||
| 177 | 32 | public function generatePackage() |
|
| 181 | /** |
||
| 182 | * Gets the struct by its name |
||
| 183 | * @uses Generator::getStructs() |
||
| 184 | * @param string $structName the original struct name |
||
| 185 | * @return Struct|null |
||
| 186 | */ |
||
| 187 | 376 | public function getStruct($structName) |
|
| 191 | /** |
||
| 192 | * Gets a service by its name |
||
| 193 | * @param string $serviceName the service name |
||
| 194 | * @return Service|null |
||
| 195 | */ |
||
| 196 | 332 | public function getService($serviceName) |
|
| 200 | /** |
||
| 201 | * Returns the method |
||
| 202 | * @uses Generator::getServiceName() |
||
| 203 | * @uses Generator::getService() |
||
| 204 | * @uses Service::getMethod() |
||
| 205 | * @param string $methodName the original function name |
||
| 206 | * @return Method|null |
||
| 207 | */ |
||
| 208 | 328 | public function getServiceMethod($methodName) |
|
| 212 | /** |
||
| 213 | * @return ServiceContainer |
||
| 214 | */ |
||
| 215 | 464 | public function getServices() |
|
| 219 | /** |
||
| 220 | * @return StructContainer |
||
| 221 | */ |
||
| 222 | 444 | public function getStructs() |
|
| 226 | /** |
||
| 227 | * Sets the optionCategory value |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | 280 | public function getOptionCategory() |
|
| 234 | /** |
||
| 235 | * Sets the optionCategory value |
||
| 236 | * @param string $category |
||
| 237 | * @return Generator |
||
| 238 | */ |
||
| 239 | 272 | public function setOptionCategory($category) |
|
| 244 | /** |
||
| 245 | * Sets the optionGatherMethods value |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | 472 | public function getOptionGatherMethods() |
|
| 252 | /** |
||
| 253 | * Sets the optionGatherMethods value |
||
| 254 | * @param string $gatherMethods |
||
| 255 | * @return Generator |
||
| 256 | */ |
||
| 257 | 272 | public function setOptionGatherMethods($gatherMethods) |
|
| 262 | /** |
||
| 263 | * Gets the optionGenericConstantsNames value |
||
| 264 | * @return bool |
||
| 265 | */ |
||
| 266 | 60 | public function getOptionGenericConstantsNames() |
|
| 270 | /** |
||
| 271 | * Sets the optionGenericConstantsNames value |
||
| 272 | * @param bool $genericConstantsNames |
||
| 273 | * @return Generator |
||
| 274 | */ |
||
| 275 | 8 | public function setOptionGenericConstantsNames($genericConstantsNames) |
|
| 280 | /** |
||
| 281 | * Gets the optionGenerateTutorialFile value |
||
| 282 | * @return bool |
||
| 283 | */ |
||
| 284 | 28 | public function getOptionGenerateTutorialFile() |
|
| 288 | /** |
||
| 289 | * Sets the optionGenerateTutorialFile value |
||
| 290 | * @param bool $generateTutorialFile |
||
| 291 | * @return Generator |
||
| 292 | */ |
||
| 293 | 4 | public function setOptionGenerateTutorialFile($generateTutorialFile) |
|
| 298 | /** |
||
| 299 | * Gets the optionNamespacePrefix value |
||
| 300 | * @return string |
||
| 301 | */ |
||
| 302 | 256 | public function getOptionNamespacePrefix() |
|
| 306 | /** |
||
| 307 | * Sets the optionGenerateTutorialFile value |
||
| 308 | * @param string $namespace |
||
| 309 | * @return Generator |
||
| 310 | */ |
||
| 311 | 20 | public function setOptionNamespacePrefix($namespace) |
|
| 316 | /** |
||
| 317 | * Gets the optionAddComments value |
||
| 318 | * @return array |
||
| 319 | */ |
||
| 320 | 204 | public function getOptionAddComments() |
|
| 324 | /** |
||
| 325 | * Sets the optionAddComments value |
||
| 326 | * @param array $addComments |
||
| 327 | * @return Generator |
||
| 328 | */ |
||
| 329 | 272 | public function setOptionAddComments($addComments) |
|
| 334 | /** |
||
| 335 | * Gets the optionStandalone value |
||
| 336 | * @return bool |
||
| 337 | */ |
||
| 338 | 60 | public function getOptionStandalone() |
|
| 342 | /** |
||
| 343 | * Sets the optionStandalone value |
||
| 344 | * @param bool $standalone |
||
| 345 | * @return Generator |
||
| 346 | */ |
||
| 347 | 8 | public function setOptionStandalone($standalone) |
|
| 352 | /** |
||
| 353 | * Gets the optionValidation value |
||
| 354 | * @return bool |
||
| 355 | */ |
||
| 356 | 112 | public function getOptionValidation() |
|
| 360 | /** |
||
| 361 | * Sets the optionValidation value |
||
| 362 | * @param bool $validation |
||
| 363 | * @return Generator |
||
| 364 | */ |
||
| 365 | 12 | public function setOptionValidation($validation) |
|
| 370 | /** |
||
| 371 | * Gets the optionStructClass value |
||
| 372 | * @return string |
||
| 373 | */ |
||
| 374 | 92 | public function getOptionStructClass() |
|
| 378 | /** |
||
| 379 | * Sets the optionStructClass value |
||
| 380 | * @param string $structClass |
||
| 381 | * @return Generator |
||
| 382 | */ |
||
| 383 | 12 | public function setOptionStructClass($structClass) |
|
| 388 | /** |
||
| 389 | * Gets the optionStructArrayClass value |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | 36 | public function getOptionStructArrayClass() |
|
| 396 | /** |
||
| 397 | * Sets the optionStructArrayClass value |
||
| 398 | * @param string $structArrayClass |
||
| 399 | * @return Generator |
||
| 400 | */ |
||
| 401 | 4 | public function setOptionStructArrayClass($structArrayClass) |
|
| 406 | /** |
||
| 407 | * Gets the optionSoapClientClass value |
||
| 408 | * @return string |
||
| 409 | */ |
||
| 410 | 92 | public function getOptionSoapClientClass() |
|
| 414 | /** |
||
| 415 | * Sets the optionSoapClientClass value |
||
| 416 | * @param string $soapClientClass |
||
| 417 | * @return Generator |
||
| 418 | */ |
||
| 419 | 4 | public function setOptionSoapClientClass($soapClientClass) |
|
| 424 | /** |
||
| 425 | * Gets the package name prefix |
||
| 426 | * @param bool $ucFirst ucfirst package name prefix or not |
||
| 427 | * @return string |
||
| 428 | */ |
||
| 429 | 536 | public function getOptionPrefix($ucFirst = true) |
|
| 433 | /** |
||
| 434 | * Sets the package name prefix |
||
| 435 | * @param string $optionPrefix |
||
| 436 | * @return Generator |
||
| 437 | */ |
||
| 438 | 296 | public function setOptionPrefix($optionPrefix) |
|
| 443 | /** |
||
| 444 | * Gets the package name suffix |
||
| 445 | * @param bool $ucFirst ucfirst package name suffix or not |
||
| 446 | * @return string |
||
| 447 | */ |
||
| 448 | 520 | public function getOptionSuffix($ucFirst = true) |
|
| 452 | /** |
||
| 453 | * Sets the package name suffix |
||
| 454 | * @param string $optionSuffix |
||
| 455 | * @return Generator |
||
| 456 | */ |
||
| 457 | 28 | public function setOptionSuffix($optionSuffix) |
|
| 462 | /** |
||
| 463 | * Gets the optionBasicLogin value |
||
| 464 | * @return string |
||
| 465 | */ |
||
| 466 | 520 | public function getOptionBasicLogin() |
|
| 470 | /** |
||
| 471 | * Sets the optionBasicLogin value |
||
| 472 | * @param string $optionBasicLogin |
||
| 473 | * @return Generator |
||
| 474 | */ |
||
| 475 | 4 | public function setOptionBasicLogin($optionBasicLogin) |
|
| 480 | /** |
||
| 481 | * Gets the optionBasicPassword value |
||
| 482 | * @return string |
||
| 483 | */ |
||
| 484 | 520 | public function getOptionBasicPassword() |
|
| 488 | /** |
||
| 489 | * Sets the optionBasicPassword value |
||
| 490 | * @param string $optionBasicPassword |
||
| 491 | * @return Generator |
||
| 492 | */ |
||
| 493 | 4 | public function setOptionBasicPassword($optionBasicPassword) |
|
| 498 | /** |
||
| 499 | * Gets the optionProxyHost value |
||
| 500 | * @return string |
||
| 501 | */ |
||
| 502 | 520 | public function getOptionProxyHost() |
|
| 506 | /** |
||
| 507 | * Sets the optionProxyHost value |
||
| 508 | * @param string $optionProxyHost |
||
| 509 | * @return Generator |
||
| 510 | */ |
||
| 511 | 4 | public function setOptionProxyHost($optionProxyHost) |
|
| 516 | /** |
||
| 517 | * Gets the optionProxyPort value |
||
| 518 | * @return string |
||
| 519 | */ |
||
| 520 | 520 | public function getOptionProxyPort() |
|
| 524 | /** |
||
| 525 | * Sets the optionProxyPort value |
||
| 526 | * @param string $optionProxyPort |
||
| 527 | * @return Generator |
||
| 528 | */ |
||
| 529 | 4 | public function setOptionProxyPort($optionProxyPort) |
|
| 534 | /** |
||
| 535 | * Gets the optionProxyLogin value |
||
| 536 | * @return string |
||
| 537 | */ |
||
| 538 | 520 | public function getOptionProxyLogin() |
|
| 542 | /** |
||
| 543 | * Sets the optionProxyLogin value |
||
| 544 | * @param string $optionProxyLogin |
||
| 545 | * @return Generator |
||
| 546 | */ |
||
| 547 | 4 | public function setOptionProxyLogin($optionProxyLogin) |
|
| 552 | /** |
||
| 553 | * Gets the optionProxyPassword value |
||
| 554 | * @return string |
||
| 555 | */ |
||
| 556 | 520 | public function getOptionProxyPassword() |
|
| 560 | /** |
||
| 561 | * Sets the optionProxyPassword value |
||
| 562 | * @param string $optionProxyPassword |
||
| 563 | * @return Generator |
||
| 564 | */ |
||
| 565 | 4 | public function setOptionProxyPassword($optionProxyPassword) |
|
| 570 | /** |
||
| 571 | * Gets the optionOrigin value |
||
| 572 | * @return string |
||
| 573 | */ |
||
| 574 | 516 | public function getOptionOrigin() |
|
| 578 | /** |
||
| 579 | * Sets the optionOrigin value |
||
| 580 | * @param string $optionOrigin |
||
| 581 | * @return Generator |
||
| 582 | */ |
||
| 583 | 4 | public function setOptionOrigin($optionOrigin) |
|
| 589 | /** |
||
| 590 | * Gets the optionDestination value |
||
| 591 | * @return string |
||
| 592 | */ |
||
| 593 | 296 | public function getOptionDestination() |
|
| 601 | /** |
||
| 602 | * Sets the optionDestination value |
||
| 603 | * @param string $optionDestination |
||
| 604 | * @return Generator |
||
| 605 | */ |
||
| 606 | 12 | public function setOptionDestination($optionDestination) |
|
| 615 | /** |
||
| 616 | * Gets the optionSoapOptions value |
||
| 617 | * @return string |
||
| 618 | */ |
||
| 619 | 512 | public function getOptionSoapOptions() |
|
| 623 | /** |
||
| 624 | * Sets the optionSoapOptions value |
||
| 625 | * @param array $optionSoapOptions |
||
| 626 | * @return Generator |
||
| 627 | */ |
||
| 628 | 4 | public function setOptionSoapOptions($optionSoapOptions) |
|
| 636 | /** |
||
| 637 | * Gets the optionComposerName value |
||
| 638 | * @return string |
||
| 639 | */ |
||
| 640 | 40 | public function getOptionComposerName() |
|
| 644 | /** |
||
| 645 | * Sets the optionComposerName value |
||
| 646 | * @param string $optionComposerName |
||
| 647 | * @return Generator |
||
| 648 | */ |
||
| 649 | 20 | public function setOptionComposerName($optionComposerName) |
|
| 658 | /** |
||
| 659 | * Gets the optionComposerSettings value |
||
| 660 | * @return array |
||
| 661 | */ |
||
| 662 | 28 | public function getOptionComposerSettings() |
|
| 666 | /** |
||
| 667 | * Sets the optionComposerSettings value |
||
| 668 | * @param array $optionComposerSettings |
||
| 669 | * @return Generator |
||
| 670 | */ |
||
| 671 | 8 | public function setOptionComposerSettings(array $optionComposerSettings = array()) |
|
| 676 | /** |
||
| 677 | * Gets the optionStructsFolder value |
||
| 678 | * @return string |
||
| 679 | */ |
||
| 680 | 260 | public function getOptionStructsFolder() |
|
| 684 | /** |
||
| 685 | * Sets the optionStructsFolder value |
||
| 686 | * @param string $optionStructsFolder |
||
| 687 | * @return Generator |
||
| 688 | */ |
||
| 689 | 4 | public function setOptionStructsFolder($optionStructsFolder) |
|
| 694 | /** |
||
| 695 | * Gets the optionArraysFolder value |
||
| 696 | * @return string |
||
| 697 | */ |
||
| 698 | 52 | public function getOptionArraysFolder() |
|
| 702 | /** |
||
| 703 | * Sets the optionArraysFolder value |
||
| 704 | * @param string $optionArraysFolder |
||
| 705 | * @return Generator |
||
| 706 | */ |
||
| 707 | 4 | public function setOptionArraysFolder($optionArraysFolder) |
|
| 712 | /** |
||
| 713 | * Gets the optionEnumsFolder value |
||
| 714 | * @return string |
||
| 715 | */ |
||
| 716 | 92 | public function getOptionEnumsFolder() |
|
| 720 | /** |
||
| 721 | * Sets the optionEnumsFolder value |
||
| 722 | * @param string $optionEnumsFolder |
||
| 723 | * @return Generator |
||
| 724 | */ |
||
| 725 | 4 | public function setOptionEnumsFolder($optionEnumsFolder) |
|
| 730 | /** |
||
| 731 | * Gets the optionServicesFolder value |
||
| 732 | * @return string |
||
| 733 | */ |
||
| 734 | 512 | public function getOptionServicesFolder() |
|
| 738 | /** |
||
| 739 | * Sets the optionServicesFolder value |
||
| 740 | * @param string $optionServicesFolder |
||
| 741 | * @return Generator |
||
| 742 | */ |
||
| 743 | 4 | public function setOptionServicesFolder($optionServicesFolder) |
|
| 748 | /** |
||
| 749 | * Gets the WSDL |
||
| 750 | * @return Wsdl|null |
||
| 751 | */ |
||
| 752 | 456 | public function getWsdl() |
|
| 756 | /** |
||
| 757 | * Sets the WSDLs |
||
| 758 | * @param Wsdl $wsdl |
||
| 759 | * @return Generator |
||
| 760 | */ |
||
| 761 | 500 | protected function setWsdl(Wsdl $wsdl) |
|
| 766 | /** |
||
| 767 | * Adds Wsdl location |
||
| 768 | * @param Wsdl $wsdl |
||
| 769 | * @param string $schemaLocation |
||
| 770 | * @return Generator |
||
| 771 | */ |
||
| 772 | 180 | public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation) |
|
| 779 | /** |
||
| 780 | * Gets gather name class |
||
| 781 | * @param AbstractModel $model the model for which we generate the folder |
||
| 782 | * @return string |
||
| 783 | */ |
||
| 784 | 448 | private function getGather(AbstractModel $model) |
|
| 788 | /** |
||
| 789 | * Returns the service name associated to the method/operation name in order to gather them in one service class |
||
| 790 | * @uses Generator::getGather() |
||
| 791 | * @param string $methodName original operation/method name |
||
| 792 | * @return string |
||
| 793 | */ |
||
| 794 | 464 | public function getServiceName($methodName) |
|
| 798 | /** |
||
| 799 | * @param GeneratorOptions $options |
||
| 800 | * @return Generator |
||
| 801 | */ |
||
| 802 | 504 | protected function setOptions(GeneratorOptions $options = null) |
|
| 807 | /** |
||
| 808 | * @return GeneratorOptions |
||
| 809 | */ |
||
| 810 | 548 | public function getOptions() |
|
| 814 | /** |
||
| 815 | * @return GeneratorSoapClient |
||
| 816 | */ |
||
| 817 | 484 | public function getSoapClient() |
|
| 821 | /** |
||
| 822 | * @param string $url |
||
| 823 | * @return string |
||
| 824 | */ |
||
| 825 | 508 | public function getUrlContent($url) |
|
| 834 | } |
||
| 835 |