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 implements \JsonSerializable |
||
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 | public function __construct(GeneratorOptions $options) |
||
56 | /** |
||
57 | * @return Generator |
||
58 | */ |
||
59 | protected function initialize() |
||
67 | /** |
||
68 | * @throws \InvalidArgumentException |
||
69 | * @return Generator |
||
70 | */ |
||
71 | protected function initSoapClient() |
||
78 | /** |
||
79 | * @return Generator |
||
80 | */ |
||
81 | protected function initContainers() |
||
88 | /** |
||
89 | * @return Generator |
||
90 | */ |
||
91 | protected function initParsers() |
||
98 | /** |
||
99 | * @return GeneratorParsers |
||
100 | */ |
||
101 | public function getParsers() |
||
105 | /** |
||
106 | * @return Generator |
||
107 | */ |
||
108 | protected function initFiles() |
||
115 | /** |
||
116 | * @return GeneratorFiles |
||
117 | */ |
||
118 | public function getFiles() |
||
122 | /** |
||
123 | * @throws \InvalidArgumentException |
||
124 | * @return Generator |
||
125 | */ |
||
126 | protected function initDirectory() |
||
134 | /** |
||
135 | * @return Generator |
||
136 | */ |
||
137 | protected function initWsdl() |
||
142 | /** |
||
143 | * @return Generator |
||
144 | */ |
||
145 | protected function doSanityChecks() |
||
157 | /** |
||
158 | * @return Generator |
||
159 | */ |
||
160 | protected function doParse() |
||
165 | /** |
||
166 | * @return Generator |
||
167 | */ |
||
168 | protected function doGenerate() |
||
173 | /** |
||
174 | * Generates all classes based on options |
||
175 | * @return Generator |
||
176 | */ |
||
177 | public function generatePackage() |
||
181 | /** |
||
182 | * Only parses what has to be parsed, called before actually generating the package |
||
183 | * @return Generator |
||
184 | */ |
||
185 | public function parse() |
||
189 | /** |
||
190 | * Gets the struct by its name |
||
191 | * @uses Generator::getStructs() |
||
192 | * @param string $structName the original struct name |
||
193 | * @return Struct|null |
||
194 | */ |
||
195 | public function getStruct($structName) |
||
199 | /** |
||
200 | * Gets a service by its name |
||
201 | * @param string $serviceName the service name |
||
202 | * @return Service|null |
||
203 | */ |
||
204 | public function getService($serviceName) |
||
208 | /** |
||
209 | * Returns the method |
||
210 | * @uses Generator::getServiceName() |
||
211 | * @uses Generator::getService() |
||
212 | * @uses Service::getMethod() |
||
213 | * @param string $methodName the original function name |
||
214 | * @return Method|null |
||
215 | */ |
||
216 | public function getServiceMethod($methodName) |
||
220 | /** |
||
221 | * @return ServiceContainer |
||
222 | */ |
||
223 | public function getServices() |
||
227 | /** |
||
228 | * @return StructContainer |
||
229 | */ |
||
230 | public function getStructs() |
||
234 | /** |
||
235 | * Sets the optionCategory value |
||
236 | * @return string |
||
237 | */ |
||
238 | public function getOptionCategory() |
||
242 | /** |
||
243 | * Sets the optionCategory value |
||
244 | * @param string $category |
||
245 | * @return Generator |
||
246 | */ |
||
247 | public function setOptionCategory($category) |
||
252 | /** |
||
253 | * Sets the optionGatherMethods value |
||
254 | * @return string |
||
255 | */ |
||
256 | public function getOptionGatherMethods() |
||
260 | /** |
||
261 | * Sets the optionGatherMethods value |
||
262 | * @param string $gatherMethods |
||
263 | * @return Generator |
||
264 | */ |
||
265 | public function setOptionGatherMethods($gatherMethods) |
||
270 | /** |
||
271 | * Gets the optionGenericConstantsNames value |
||
272 | * @return bool |
||
273 | */ |
||
274 | public function getOptionGenericConstantsNames() |
||
278 | /** |
||
279 | * Sets the optionGenericConstantsNames value |
||
280 | * @param bool $genericConstantsNames |
||
281 | * @return Generator |
||
282 | */ |
||
283 | public function setOptionGenericConstantsNames($genericConstantsNames) |
||
288 | /** |
||
289 | * Gets the optionGenerateTutorialFile value |
||
290 | * @return bool |
||
291 | */ |
||
292 | public function getOptionGenerateTutorialFile() |
||
296 | /** |
||
297 | * Sets the optionGenerateTutorialFile value |
||
298 | * @param bool $generateTutorialFile |
||
299 | * @return Generator |
||
300 | */ |
||
301 | public function setOptionGenerateTutorialFile($generateTutorialFile) |
||
306 | /** |
||
307 | * Gets the optionNamespacePrefix value |
||
308 | * @return string |
||
309 | */ |
||
310 | public function getOptionNamespacePrefix() |
||
314 | /** |
||
315 | * Sets the optionGenerateTutorialFile value |
||
316 | * @param string $namespace |
||
317 | * @return Generator |
||
318 | */ |
||
319 | public function setOptionNamespacePrefix($namespace) |
||
324 | /** |
||
325 | * Gets the optionAddComments value |
||
326 | * @return array |
||
327 | */ |
||
328 | public function getOptionAddComments() |
||
332 | /** |
||
333 | * Sets the optionAddComments value |
||
334 | * @param array $addComments |
||
335 | * @return Generator |
||
336 | */ |
||
337 | public function setOptionAddComments($addComments) |
||
342 | /** |
||
343 | * Gets the optionStandalone value |
||
344 | * @return bool |
||
345 | */ |
||
346 | public function getOptionStandalone() |
||
350 | /** |
||
351 | * Sets the optionStandalone value |
||
352 | * @param bool $standalone |
||
353 | * @return Generator |
||
354 | */ |
||
355 | public function setOptionStandalone($standalone) |
||
360 | /** |
||
361 | * Gets the optionValidation value |
||
362 | * @return bool |
||
363 | */ |
||
364 | public function getOptionValidation() |
||
368 | /** |
||
369 | * Sets the optionValidation value |
||
370 | * @param bool $validation |
||
371 | * @return Generator |
||
372 | */ |
||
373 | public function setOptionValidation($validation) |
||
378 | /** |
||
379 | * Gets the optionStructClass value |
||
380 | * @return string |
||
381 | */ |
||
382 | public function getOptionStructClass() |
||
386 | /** |
||
387 | * Sets the optionStructClass value |
||
388 | * @param string $structClass |
||
389 | * @return Generator |
||
390 | */ |
||
391 | public function setOptionStructClass($structClass) |
||
396 | /** |
||
397 | * Gets the optionStructArrayClass value |
||
398 | * @return string |
||
399 | */ |
||
400 | public function getOptionStructArrayClass() |
||
404 | /** |
||
405 | * Sets the optionStructArrayClass value |
||
406 | * @param string $structArrayClass |
||
407 | * @return Generator |
||
408 | */ |
||
409 | public function setOptionStructArrayClass($structArrayClass) |
||
414 | /** |
||
415 | * Gets the optionSoapClientClass value |
||
416 | * @return string |
||
417 | */ |
||
418 | public function getOptionSoapClientClass() |
||
422 | /** |
||
423 | * Sets the optionSoapClientClass value |
||
424 | * @param string $soapClientClass |
||
425 | * @return Generator |
||
426 | */ |
||
427 | public function setOptionSoapClientClass($soapClientClass) |
||
432 | /** |
||
433 | * Gets the package name prefix |
||
434 | * @param bool $ucFirst ucfirst package name prefix or not |
||
435 | * @return string |
||
436 | */ |
||
437 | public function getOptionPrefix($ucFirst = true) |
||
441 | /** |
||
442 | * Sets the package name prefix |
||
443 | * @param string $optionPrefix |
||
444 | * @return Generator |
||
445 | */ |
||
446 | public function setOptionPrefix($optionPrefix) |
||
451 | /** |
||
452 | * Gets the package name suffix |
||
453 | * @param bool $ucFirst ucfirst package name suffix or not |
||
454 | * @return string |
||
455 | */ |
||
456 | public function getOptionSuffix($ucFirst = true) |
||
460 | /** |
||
461 | * Sets the package name suffix |
||
462 | * @param string $optionSuffix |
||
463 | * @return Generator |
||
464 | */ |
||
465 | public function setOptionSuffix($optionSuffix) |
||
470 | /** |
||
471 | * Gets the optionBasicLogin value |
||
472 | * @return string |
||
473 | */ |
||
474 | public function getOptionBasicLogin() |
||
478 | /** |
||
479 | * Sets the optionBasicLogin value |
||
480 | * @param string $optionBasicLogin |
||
481 | * @return Generator |
||
482 | */ |
||
483 | public function setOptionBasicLogin($optionBasicLogin) |
||
488 | /** |
||
489 | * Gets the optionBasicPassword value |
||
490 | * @return string |
||
491 | */ |
||
492 | public function getOptionBasicPassword() |
||
496 | /** |
||
497 | * Sets the optionBasicPassword value |
||
498 | * @param string $optionBasicPassword |
||
499 | * @return Generator |
||
500 | */ |
||
501 | public function setOptionBasicPassword($optionBasicPassword) |
||
506 | /** |
||
507 | * Gets the optionProxyHost value |
||
508 | * @return string |
||
509 | */ |
||
510 | public function getOptionProxyHost() |
||
514 | /** |
||
515 | * Sets the optionProxyHost value |
||
516 | * @param string $optionProxyHost |
||
517 | * @return Generator |
||
518 | */ |
||
519 | public function setOptionProxyHost($optionProxyHost) |
||
524 | /** |
||
525 | * Gets the optionProxyPort value |
||
526 | * @return string |
||
527 | */ |
||
528 | public function getOptionProxyPort() |
||
532 | /** |
||
533 | * Sets the optionProxyPort value |
||
534 | * @param string $optionProxyPort |
||
535 | * @return Generator |
||
536 | */ |
||
537 | public function setOptionProxyPort($optionProxyPort) |
||
542 | /** |
||
543 | * Gets the optionProxyLogin value |
||
544 | * @return string |
||
545 | */ |
||
546 | public function getOptionProxyLogin() |
||
550 | /** |
||
551 | * Sets the optionProxyLogin value |
||
552 | * @param string $optionProxyLogin |
||
553 | * @return Generator |
||
554 | */ |
||
555 | public function setOptionProxyLogin($optionProxyLogin) |
||
560 | /** |
||
561 | * Gets the optionProxyPassword value |
||
562 | * @return string |
||
563 | */ |
||
564 | public function getOptionProxyPassword() |
||
568 | /** |
||
569 | * Sets the optionProxyPassword value |
||
570 | * @param string $optionProxyPassword |
||
571 | * @return Generator |
||
572 | */ |
||
573 | public function setOptionProxyPassword($optionProxyPassword) |
||
578 | /** |
||
579 | * Gets the optionOrigin value |
||
580 | * @return string |
||
581 | */ |
||
582 | public function getOptionOrigin() |
||
586 | /** |
||
587 | * Sets the optionOrigin value |
||
588 | * @param string $optionOrigin |
||
589 | * @return Generator |
||
590 | */ |
||
591 | public function setOptionOrigin($optionOrigin) |
||
597 | /** |
||
598 | * Gets the optionDestination value |
||
599 | * @return string |
||
600 | */ |
||
601 | public function getOptionDestination() |
||
609 | /** |
||
610 | * Sets the optionDestination value |
||
611 | * @param string $optionDestination |
||
612 | * @return Generator |
||
613 | */ |
||
614 | public function setOptionDestination($optionDestination) |
||
623 | /** |
||
624 | * Gets the optionSrcDiname value |
||
625 | * @return string |
||
626 | */ |
||
627 | public function getOptionSrcDirname() |
||
631 | /** |
||
632 | * Sets the optionSrcDirname value |
||
633 | * @param string $optionSrcDirname |
||
634 | * @return Generator |
||
635 | */ |
||
636 | public function setOptionSrcDirname($optionSrcDirname) |
||
641 | /** |
||
642 | * Gets the optionSoapOptions value |
||
643 | * @return string |
||
644 | */ |
||
645 | public function getOptionSoapOptions() |
||
649 | /** |
||
650 | * Sets the optionSoapOptions value |
||
651 | * @param array $optionSoapOptions |
||
652 | * @return Generator |
||
653 | */ |
||
654 | public function setOptionSoapOptions($optionSoapOptions) |
||
662 | /** |
||
663 | * Gets the optionComposerName value |
||
664 | * @return string |
||
665 | */ |
||
666 | public function getOptionComposerName() |
||
670 | /** |
||
671 | * Sets the optionComposerName value |
||
672 | * @param string $optionComposerName |
||
673 | * @return Generator |
||
674 | */ |
||
675 | public function setOptionComposerName($optionComposerName) |
||
684 | /** |
||
685 | * Gets the optionComposerSettings value |
||
686 | * @return array |
||
687 | */ |
||
688 | public function getOptionComposerSettings() |
||
692 | /** |
||
693 | * Sets the optionComposerSettings value |
||
694 | * @param array $optionComposerSettings |
||
695 | * @return Generator |
||
696 | */ |
||
697 | public function setOptionComposerSettings(array $optionComposerSettings = array()) |
||
702 | /** |
||
703 | * Gets the optionStructsFolder value |
||
704 | * @return string |
||
705 | */ |
||
706 | public function getOptionStructsFolder() |
||
710 | /** |
||
711 | * Sets the optionStructsFolder value |
||
712 | * @param string $optionStructsFolder |
||
713 | * @return Generator |
||
714 | */ |
||
715 | public function setOptionStructsFolder($optionStructsFolder) |
||
720 | /** |
||
721 | * Gets the optionArraysFolder value |
||
722 | * @return string |
||
723 | */ |
||
724 | public function getOptionArraysFolder() |
||
728 | /** |
||
729 | * Sets the optionArraysFolder value |
||
730 | * @param string $optionArraysFolder |
||
731 | * @return Generator |
||
732 | */ |
||
733 | public function setOptionArraysFolder($optionArraysFolder) |
||
738 | /** |
||
739 | * Gets the optionEnumsFolder value |
||
740 | * @return string |
||
741 | */ |
||
742 | public function getOptionEnumsFolder() |
||
746 | /** |
||
747 | * Sets the optionEnumsFolder value |
||
748 | * @param string $optionEnumsFolder |
||
749 | * @return Generator |
||
750 | */ |
||
751 | public function setOptionEnumsFolder($optionEnumsFolder) |
||
756 | /** |
||
757 | * Gets the optionServicesFolder value |
||
758 | * @return string |
||
759 | */ |
||
760 | public function getOptionServicesFolder() |
||
764 | /** |
||
765 | * Sets the optionServicesFolder value |
||
766 | * @param string $optionServicesFolder |
||
767 | * @return Generator |
||
768 | */ |
||
769 | public function setOptionServicesFolder($optionServicesFolder) |
||
774 | /** |
||
775 | * Gets the WSDL |
||
776 | * @return Wsdl|null |
||
777 | */ |
||
778 | public function getWsdl() |
||
782 | /** |
||
783 | * Sets the WSDLs |
||
784 | * @param Wsdl $wsdl |
||
785 | * @return Generator |
||
786 | */ |
||
787 | protected function setWsdl(Wsdl $wsdl) |
||
792 | /** |
||
793 | * Adds Wsdl location |
||
794 | * @param Wsdl $wsdl |
||
795 | * @param string $schemaLocation |
||
796 | * @return Generator |
||
797 | */ |
||
798 | public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation) |
||
805 | /** |
||
806 | * Gets gather name class |
||
807 | * @param AbstractModel $model the model for which we generate the folder |
||
808 | * @return string |
||
809 | */ |
||
810 | private function getGather(AbstractModel $model) |
||
814 | /** |
||
815 | * Returns the service name associated to the method/operation name in order to gather them in one service class |
||
816 | * @uses Generator::getGather() |
||
817 | * @param string $methodName original operation/method name |
||
818 | * @return string |
||
819 | */ |
||
820 | public function getServiceName($methodName) |
||
824 | /** |
||
825 | * @param GeneratorOptions $options |
||
826 | * @return Generator |
||
827 | */ |
||
828 | protected function setOptions(GeneratorOptions $options = null) |
||
833 | /** |
||
834 | * @return GeneratorOptions |
||
835 | */ |
||
836 | public function getOptions() |
||
840 | /** |
||
841 | * @return GeneratorSoapClient |
||
842 | */ |
||
843 | public function getSoapClient() |
||
847 | /** |
||
848 | * @param string $url |
||
849 | * @return string |
||
850 | */ |
||
851 | public function getUrlContent($url) |
||
860 | /** |
||
861 | * @return GeneratorContainers |
||
862 | */ |
||
863 | public function getContainers() |
||
867 | /** |
||
868 | * @return array |
||
869 | */ |
||
870 | public function jsonSerialize() |
||
877 | /** |
||
878 | * @param string $json |
||
879 | * @throws \InvalidArgumentException |
||
880 | * @return Generator |
||
881 | */ |
||
882 | public static function instanceFromSerializedJson($json) |
||
906 | /** |
||
907 | * @param Generator $generator |
||
908 | * @param array $jsonArrayEntry |
||
909 | * @return AbstractModel |
||
910 | */ |
||
911 | private static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry) |
||
915 | } |
||
916 |