Complex classes like WSDL 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 WSDL, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class WSDL |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * The DOMDocument instance. |
||
18 | * |
||
19 | * @var DOMDocument |
||
20 | */ |
||
21 | private $dom; |
||
22 | |||
23 | /** |
||
24 | * The WSDL node from the full DOMDocument. |
||
25 | * |
||
26 | * @var DOMDocument |
||
27 | */ |
||
28 | private $wsdl; |
||
29 | |||
30 | /** |
||
31 | * Schema node of the WSDL. |
||
32 | * |
||
33 | * @var DOMElement |
||
34 | */ |
||
35 | private $schema; |
||
36 | |||
37 | /** |
||
38 | * Types defined on schema. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | private $includedTypes; |
||
43 | |||
44 | /** |
||
45 | * Default XSD Types. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected static $XSDTypes = array( |
||
50 | 'string' => 'xsd:string', |
||
51 | 'bool' => 'xsd:boolean', |
||
52 | 'boolean' => 'xsd:boolean', |
||
53 | 'int' => 'xsd:int', |
||
54 | 'integer' => 'xsd:int', |
||
55 | 'double' => 'xsd:float', |
||
56 | 'float' => 'xsd:float', |
||
57 | 'decimal' => 'xsd:decimal', |
||
58 | 'array' => 'soap-enc:Array', |
||
59 | 'time' => 'xsd:time', |
||
60 | 'date' => 'xsd:date', |
||
61 | 'datetime' => 'xsd:dateTime', |
||
62 | 'anytype' => 'xsd:anyType', |
||
63 | 'unknown_type' => 'xsd:anyType', |
||
64 | 'mixed' => 'xsd:anyType', |
||
65 | 'object' => 'xsd:struct', |
||
66 | 'base64binary' => 'xsd:base64Binary' |
||
67 | ); |
||
68 | |||
69 | /** |
||
70 | * Constructor. |
||
71 | * |
||
72 | * @param string $name The name of the web service. |
||
73 | * @param string $uri URI where the WSDL will be available. |
||
74 | * @param string $xslUri The URI to the stylesheet. |
||
75 | * @throws RuntimeException If the DOM Document can not be created. |
||
76 | */ |
||
77 | 33 | public function __construct($name, $uri, $xslUri = null) |
|
108 | |||
109 | /** |
||
110 | * Set the stylesheet for the WSDL. |
||
111 | * |
||
112 | * @param string $xslUri The URI to the stylesheet. |
||
113 | * @return WSDL |
||
114 | */ |
||
115 | 3 | private function setStylesheet($xslUri) |
|
120 | |||
121 | /** |
||
122 | * Add a message element to the WSDL. |
||
123 | * |
||
124 | * @param string $name The name for the message. |
||
125 | * @param array $parts Array of parts for the message ('name'=>'type' or 'name'=>array('type'=>'type', 'element'=>'element')). |
||
126 | * @return DOMElement |
||
127 | * @link http://www.w3.org/TR/wsdl#_messages |
||
128 | */ |
||
129 | 30 | public function addMessage($name, array $parts) |
|
152 | |||
153 | /** |
||
154 | * Add a portType to element to the WSDL. |
||
155 | * |
||
156 | * @param string $name The name of the portType. |
||
157 | * @return DOMElement |
||
158 | */ |
||
159 | 33 | public function addPortType($name) |
|
167 | |||
168 | /** |
||
169 | * Add a binding element to the WSDL. |
||
170 | * |
||
171 | * @param string $name The name of the binding. |
||
172 | * @param string $portType The portType to bind. |
||
173 | * @return DOMElement |
||
174 | */ |
||
175 | 33 | public function addBinding($name, $portType) |
|
185 | |||
186 | /** |
||
187 | * Add a SOAP binding element to the Binding element. |
||
188 | * |
||
189 | * @param DOMElement $binding The binding element (from addBinding() method). |
||
190 | * @param string $style The binding style (rpc or document). |
||
191 | * @param string $transport The transport method. |
||
192 | * @return DOMElement |
||
193 | * @link http://www.w3.org/TR/wsdl#_soap:binding |
||
194 | */ |
||
195 | 33 | public function addSoapBinding( |
|
208 | |||
209 | /** |
||
210 | * Add an operation to a binding element. |
||
211 | * |
||
212 | * @param DOMElement $binding The binding element (from addBinding() method). |
||
213 | * @param string $name The name of the operation. |
||
214 | * @param array $input Attributes for the input element (use, namespace, encodingStyle). |
||
215 | * @param array $output Attributes for the output element (use, namespace, encodingStyle). |
||
216 | * @return DOMElement |
||
217 | * @link http://www.w3.org/TR/wsdl#_soap:body |
||
218 | */ |
||
219 | 30 | public function addBindingOperation(DOMElement $binding, $name, array $input = null, array $output = null) |
|
250 | |||
251 | /** |
||
252 | * Add an operation element to a portType element. |
||
253 | * |
||
254 | * @param DOMElement $portType The port type element (from addPortType() method). |
||
255 | * @param string $name The name of the operation. |
||
256 | * @param string $inputMessage The input message. |
||
257 | * @param string $outputMessage The output message. |
||
258 | * @return DOMElement |
||
259 | * @link http://www.w3.org/TR/wsdl#_request-response |
||
260 | */ |
||
261 | 30 | public function addPortOperation(DOMElement $portType, $name, $inputMessage = null, $outputMessage = null) |
|
282 | |||
283 | /** |
||
284 | * Add a SOAP operation to an operation element. |
||
285 | * |
||
286 | * @param DOMElement $binding The binding element (from addBindingOperation() method). |
||
287 | * @param string $soapAction SOAP Action. |
||
288 | * @return DOMElement |
||
289 | * @link http://www.w3.org/TR/wsdl#_soap:operation |
||
290 | */ |
||
291 | 30 | public function addSoapOperation(DOMElement $binding, $soapAction) |
|
300 | |||
301 | /** |
||
302 | * Add a service element to the WSDL. |
||
303 | * |
||
304 | * @param string $name Service name. |
||
305 | * @param string $portName Port name. |
||
306 | * @param string $binding Binding for the port. |
||
307 | * @param string $location SOAP Address location. |
||
308 | * @return DOMElement |
||
309 | * @link http://www.w3.org/TR/wsdl#_services |
||
310 | */ |
||
311 | 33 | public function addService($name, $portName, $binding, $location) |
|
330 | |||
331 | /** |
||
332 | * Add a documentation element to another element in the WSDL. |
||
333 | * |
||
334 | * @param DOMElement $inputElement The DOMElement element to add the documentation. |
||
335 | * @param string $documentation The documentation text. |
||
336 | * @return DOMElement |
||
337 | * @link http://www.w3.org/TR/wsdl#_documentation |
||
338 | */ |
||
339 | 9 | public function addDocumentation(DOMElement $inputElement, $documentation) |
|
359 | |||
360 | /** |
||
361 | * Add a complex type. |
||
362 | * |
||
363 | * @param string $type The type. |
||
364 | * @param string $wsdlType The WSDL type. |
||
365 | */ |
||
366 | 15 | public function addType($type, $wsdlType) |
|
370 | |||
371 | /** |
||
372 | * Get the XSD Type from a PHP type. |
||
373 | * |
||
374 | * @param string $type The type to get the XSD type from. |
||
375 | * @return string |
||
376 | */ |
||
377 | 30 | public function getXSDType($type) |
|
393 | |||
394 | /** |
||
395 | * Check if a type is a XDS. |
||
396 | * |
||
397 | * @param string $type The type to check. |
||
398 | * @return boolean |
||
399 | */ |
||
400 | 30 | private function isXDSType($type) |
|
405 | |||
406 | /** |
||
407 | * Add a complex type. |
||
408 | * |
||
409 | * @param string $type Name of the class. |
||
410 | * @return string |
||
411 | */ |
||
412 | 15 | public function addComplexType($type) |
|
466 | |||
467 | /** |
||
468 | * Add an array of complex type. |
||
469 | * |
||
470 | * @param string $singularType The type name without the '[]'. |
||
471 | * @param string $type The original type name. |
||
472 | * @return string |
||
473 | */ |
||
474 | 3 | protected function addComplexTypeArray($singularType, $type) |
|
505 | |||
506 | /** |
||
507 | * Parse an xsd:element represented as an array into a DOMElement. |
||
508 | * |
||
509 | * @param array $element An xsd:element represented as an array. |
||
510 | * @return DOMElement |
||
511 | */ |
||
512 | private function parseElement(array $element) |
||
538 | |||
539 | /** |
||
540 | * Add an xsd:element represented as an array to the schema. |
||
541 | * |
||
542 | * @param array $element An xsd:element represented as an array. |
||
543 | * @return string |
||
544 | */ |
||
545 | public function addElement(array $element) |
||
551 | |||
552 | /** |
||
553 | * Dump the WSDL as XML string. |
||
554 | * |
||
555 | * @param bool $formatOutput Format output |
||
556 | * @return mixed |
||
557 | */ |
||
558 | 33 | public function dump($formatOutput = true) |
|
567 | |||
568 | /** |
||
569 | * Dump the WSDL as file. |
||
570 | * |
||
571 | * @param string $filename Filename to dump |
||
572 | * @param bool $formatOutput Format output |
||
573 | * @return mixed |
||
574 | */ |
||
575 | public function save($filename, $formatOutput = true) |
||
584 | |||
585 | /** |
||
586 | * Convert a PHP type into QName. |
||
587 | * |
||
588 | * @param string $type The PHP type. |
||
589 | * @return string |
||
590 | */ |
||
591 | 33 | public static function typeToQName($type) |
|
599 | |||
600 | /** |
||
601 | * Changes the xs:all to an xs:sequence node |
||
602 | * |
||
603 | * @param \DOMElement $all |
||
604 | * @return \DOMElement |
||
605 | */ |
||
606 | 6 | private function changeAllToSequence($all) |
|
622 | |||
623 | } |
||
624 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..