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) |
|
90 | /** |
||
91 | * @param MethodContainer $methods |
||
92 | * @return Service |
||
93 | */ |
||
94 | 84 | protected function addSoapHeaderMethods(MethodContainer $methods) |
|
101 | /** |
||
102 | * @param MethodContainer $methods |
||
103 | * @param MethodModel $method |
||
104 | * @return Service |
||
105 | */ |
||
106 | 84 | protected function addSoapHeaderFromMethod(MethodContainer $methods, MethodModel $method) |
|
121 | /** |
||
122 | * @param string $methodName |
||
123 | * @param string $soapHeaderName |
||
124 | * @param string $soapHeaderNamespace |
||
125 | * @param string $soapHeaderType |
||
126 | * @return PhpMethod |
||
127 | */ |
||
128 | 20 | protected function getSoapHeaderMethod($methodName, $soapHeaderName, $soapHeaderNamespace, $soapHeaderType) |
|
143 | /** |
||
144 | * @param string $name |
||
145 | * @param bool $namespaced |
||
146 | * @return string |
||
147 | */ |
||
148 | 20 | protected function getTypeFromName($name, $namespaced = false) |
|
157 | /** |
||
158 | * @param string $soapHeaderName |
||
159 | * @return string |
||
160 | */ |
||
161 | 20 | protected function getSoapHeaderMethodName($soapHeaderName) |
|
165 | /** |
||
166 | * @param MethodContainer $methods |
||
167 | * @return Service |
||
168 | */ |
||
169 | 84 | protected function addOperationsMethods(MethodContainer $methods) |
|
176 | /** |
||
177 | * @param MethodContainer $methods |
||
178 | * @return Service |
||
179 | */ |
||
180 | 84 | protected function addGetResultMethod(MethodContainer $methods) |
|
187 | /** |
||
188 | * @param MethodContainer $methods |
||
189 | * @param MethodModel $method |
||
190 | * @return Service |
||
191 | */ |
||
192 | 84 | protected function addMainMethod(MethodContainer $methods, MethodModel $method) |
|
200 | /** |
||
201 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getMethodAnnotationBlock() |
||
202 | */ |
||
203 | 84 | protected function getMethodAnnotationBlock(PhpMethod $method) |
|
215 | /** |
||
216 | * @param PhpAnnotationBlock $annotationBlock |
||
217 | * @param PhpMethod $method |
||
218 | * @return Service |
||
219 | */ |
||
220 | 20 | protected function addAnnotationBlockForSoapHeaderMethod(PhpAnnotationBlock $annotationBlock, PhpMethod $method) |
|
235 | /** |
||
236 | * @param PhpAnnotationBlock $annotationBlock |
||
237 | * @param PhpMethod $method |
||
238 | * @return Service |
||
239 | */ |
||
240 | 84 | protected function addAnnotationBlockForOperationMethod(PhpAnnotationBlock $annotationBlock, PhpMethod $method) |
|
248 | /** |
||
249 | * @param PhpAnnotationBlock $annotationBlock |
||
250 | * @return Service |
||
251 | */ |
||
252 | 84 | protected function addAnnnotationBlockForgetResultMethod(PhpAnnotationBlock $annotationBlock) |
|
257 | /** |
||
258 | * @return string |
||
259 | */ |
||
260 | 84 | protected function getServiceReturnTypes() |
|
269 | /** |
||
270 | * @param MethodModel $method |
||
271 | * @return string |
||
272 | */ |
||
273 | 84 | public static function getOperationMethodReturnType(MethodModel $method, Generator $generator) |
|
289 | /** |
||
290 | * @param PhpMethod $method |
||
291 | * @return MethodModel|null |
||
292 | */ |
||
293 | 84 | protected function getModelFromMethod(PhpMethod $method) |
|
301 | /** |
||
302 | * @param PhpMethod $phpMethod |
||
303 | * @param MethodModel $methodModel |
||
304 | * @return Service |
||
305 | */ |
||
306 | 84 | protected function setModelFromMethod(PhpMethod $phpMethod, MethodModel $methodModel) |
|
311 | /** |
||
312 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getModel() |
||
313 | * @return ServiceModel |
||
314 | */ |
||
315 | 88 | public function getModel() |
|
319 | /** |
||
320 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::setModel() |
||
321 | * @throws \InvalidaArgumentException |
||
322 | * @param AbstractModel $model |
||
323 | * @return Service |
||
324 | */ |
||
325 | 92 | public function setModel(AbstractModel $model) |
|
332 | } |
||
333 |