Complex classes like Service 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 Service, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class Service extends AbstractModelFile |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | const METHOD_SET_HEADER_PREFIX = 'setSoapHeader'; |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | const PARAM_SET_HEADER_NAMESPACE = 'nameSpace'; |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | const PARAM_SET_HEADER_MUSTUNDERSTAND = 'mustUnderstand'; |
||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | const PARAM_SET_HEADER_ACTOR = 'actor'; |
||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | const METHOD_GET_RESULT = 'getResult'; |
||
44 | /** |
||
45 | * Method model can't be found in case the original method's name is unclean: |
||
46 | * - ex: my.operation.name becomes my_operation_name |
||
47 | * thus the Model from Model\Service::getMethod() can't be found |
||
48 | * So we store the generated name associated to the original method object |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $methods = array(); |
||
52 | /** |
||
53 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassConstants() |
||
54 | */ |
||
55 | 84 | protected function getClassConstants(ConstantContainer $constants) |
|
58 | /** |
||
59 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getConstantAnnotationBlock() |
||
60 | */ |
||
61 | protected function getConstantAnnotationBlock(PhpConstant $constant) |
||
64 | /** |
||
65 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassProperties() |
||
66 | */ |
||
67 | 84 | protected function getClassProperties(PropertyContainer $properties) |
|
70 | /** |
||
71 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getPropertyAnnotationBlock() |
||
72 | */ |
||
73 | protected function getPropertyAnnotationBlock(PhpProperty $property) |
||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | 84 | protected function getClassDeclarationLineText() |
|
83 | /** |
||
84 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassMethods() |
||
85 | */ |
||
86 | 84 | protected function getClassMethods(MethodContainer $methods) |
|
93 | /** |
||
94 | * @param MethodContainer $methods |
||
95 | * @return Service |
||
96 | */ |
||
97 | 84 | protected function addSoapHeaderMethods(MethodContainer $methods) |
|
104 | /** |
||
105 | * @param MethodContainer $methods |
||
106 | * @param MethodModel $method |
||
107 | */ |
||
108 | 84 | protected function addSoapHeaderFromMethod(MethodContainer $methods, MethodModel $method) |
|
123 | /** |
||
124 | * @param string $methodName |
||
125 | * @param string $soapHeaderName |
||
126 | * @param string $soapHeaderNamespace |
||
127 | * @param string $soapHeaderType |
||
128 | * @return PhpMethod |
||
129 | */ |
||
130 | 20 | protected function getSoapHeaderMethod($methodName, $soapHeaderName, $soapHeaderNamespace, $soapHeaderType) |
|
151 | /** |
||
152 | * @param string $name |
||
153 | * @param bool $namespaced |
||
154 | * @return string |
||
155 | */ |
||
156 | 20 | protected function getTypeFromName($name, $namespaced = false) |
|
165 | /** |
||
166 | * @param string $soapHeaderName |
||
167 | * @return string |
||
168 | */ |
||
169 | 20 | protected function getSoapHeaderMethodName($soapHeaderName) |
|
173 | /** |
||
174 | * @param MethodContainer $methods |
||
175 | * @return Service |
||
176 | */ |
||
177 | 84 | protected function addOperationsMethods(MethodContainer $methods) |
|
184 | /** |
||
185 | * @param MethodContainer $methods |
||
186 | * @return Service |
||
187 | */ |
||
188 | 84 | protected function addGetResultMethod(MethodContainer $methods) |
|
195 | /** |
||
196 | * @param MethodContainer $methods |
||
197 | * @param MethodModel $method |
||
198 | * @return Service |
||
199 | */ |
||
200 | 84 | protected function addMainMethod(MethodContainer $methods, MethodModel $method) |
|
208 | /** |
||
209 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getMethodAnnotationBlock() |
||
210 | */ |
||
211 | 84 | protected function getMethodAnnotationBlock(PhpMethod $method) |
|
223 | /** |
||
224 | * @param PhpAnnotationBlock $annotationBlock |
||
225 | * @param PhpMethod $method |
||
226 | * @return Service |
||
227 | */ |
||
228 | 20 | protected function addAnnotationBlockForSoapHeaderMethod(PhpAnnotationBlock $annotationBlock, PhpMethod $method) |
|
244 | /** |
||
245 | * @param PhpAnnotationBlock $annotationBlock |
||
246 | * @param PhpMethod $method |
||
247 | * @return Service |
||
248 | */ |
||
249 | 84 | protected function addAnnotationBlockForOperationMethod(PhpAnnotationBlock $annotationBlock, PhpMethod $method) |
|
257 | /** |
||
258 | * @param PhpAnnotationBlock $annotationBlock |
||
259 | * @return Service |
||
260 | */ |
||
261 | 84 | protected function addAnnnotationBlockForgetResultMethod(PhpAnnotationBlock $annotationBlock) |
|
269 | /** |
||
270 | * @return string |
||
271 | */ |
||
272 | 84 | protected function getServiceReturnTypes() |
|
281 | /** |
||
282 | * @param MethodModel $method |
||
283 | * @return string |
||
284 | */ |
||
285 | 84 | public static function getOperationMethodReturnType(MethodModel $method, Generator $generator) |
|
301 | /** |
||
302 | * @param PhpMethod $method |
||
303 | * @return MethodModel|null |
||
304 | */ |
||
305 | 84 | protected function getModelFromMethod(PhpMethod $method) |
|
313 | /** |
||
314 | * @param PhpMethod $phpMethod |
||
315 | * @param MethodModel $methodModel |
||
316 | * @return Service |
||
317 | */ |
||
318 | 84 | protected function setModelFromMethod(PhpMethod $phpMethod, MethodModel $methodModel) |
|
323 | /** |
||
324 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getModel() |
||
325 | * @return ServiceModel |
||
326 | */ |
||
327 | 88 | public function getModel() |
|
331 | /** |
||
332 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::setModel() |
||
333 | * @throws \InvalidaArgumentException |
||
334 | * @param AbstractModel $model |
||
335 | * @return Service |
||
336 | */ |
||
337 | 92 | public function setModel(AbstractModel $model) |
|
344 | } |
||
345 |