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 | ); |
||
67 | |||
68 | /** |
||
69 | * Constructor. |
||
70 | * |
||
71 | * @param string $name The name of the web service. |
||
72 | * @param string $uri URI where the WSDL will be available. |
||
73 | * @param string $xslUri The URI to the stylesheet. |
||
74 | 24 | * @throws RuntimeException If the DOM Document can not be created. |
|
75 | */ |
||
76 | 24 | public function __construct($name, $uri, $xslUri = null) |
|
107 | |||
108 | /** |
||
109 | * Set the stylesheet for the WSDL. |
||
110 | 24 | * |
|
111 | * @param string $xslUri The URI to the stylesheet. |
||
112 | 24 | * @return WSDL |
|
113 | 24 | */ |
|
114 | private function setStylesheet($xslUri) |
||
119 | 24 | ||
120 | 24 | /** |
|
121 | 24 | * Add a message element to the WSDL. |
|
122 | 24 | * |
|
123 | * @param string $name The name for the message. |
||
124 | * @param array $parts Array of parts for the message ('name'=>'type' or 'name'=>array('type'=>'type', 'element'=>'element')). |
||
125 | * @return DOMElement |
||
126 | 24 | * @link http://www.w3.org/TR/wsdl#_messages |
|
127 | 24 | */ |
|
128 | public function addMessage($name, array $parts) |
||
151 | |||
152 | /** |
||
153 | * Add a portType to element to the WSDL. |
||
154 | * |
||
155 | * @param string $name The name of the portType. |
||
156 | 24 | * @return DOMElement |
|
157 | */ |
||
158 | 24 | public function addPortType($name) |
|
166 | |||
167 | /** |
||
168 | * Add a binding element to the WSDL. |
||
169 | * |
||
170 | * @param string $name The name of the binding. |
||
171 | * @param string $portType The portType to bind. |
||
172 | * @return DOMElement |
||
173 | */ |
||
174 | public function addBinding($name, $portType) |
||
184 | |||
185 | 24 | /** |
|
186 | * Add a SOAP binding element to the Binding element. |
||
187 | 24 | * |
|
188 | * @param DOMElement $binding The binding element (from addBinding() method). |
||
189 | * @param string $style The binding style (rpc or document). |
||
190 | * @param string $transport The transport method. |
||
191 | * @return DOMElement |
||
192 | * @link http://www.w3.org/TR/wsdl#_soap:binding |
||
193 | */ |
||
194 | public function addSoapBinding( |
||
207 | 24 | ||
208 | 24 | /** |
|
209 | 24 | * Add an operation to a binding element. |
|
210 | 24 | * |
|
211 | * @param DOMElement $binding The binding element (from addBinding() method). |
||
212 | 24 | * @param string $name The name of the operation. |
|
213 | 24 | * @param array $input Attributes for the input element (use, namespace, encodingStyle). |
|
214 | 24 | * @param array $output Attributes for the output element (use, namespace, encodingStyle). |
|
215 | * @return DOMElement |
||
216 | 24 | * @link http://www.w3.org/TR/wsdl#_soap:body |
|
217 | 24 | */ |
|
218 | 24 | public function addBindingOperation(DOMElement $binding, $name, array $input = null, array $output = null) |
|
249 | 24 | ||
250 | 24 | /** |
|
251 | 24 | * Add an operation element to a portType element. |
|
252 | * |
||
253 | 24 | * @param DOMElement $portType The port type element (from addPortType() method). |
|
254 | 9 | * @param string $name The name of the operation. |
|
255 | 9 | * @param string $inputMessage The input message. |
|
256 | 9 | * @param string $outputMessage The output message. |
|
257 | 9 | * @return DOMElement |
|
258 | * @link http://www.w3.org/TR/wsdl#_request-response |
||
259 | 24 | */ |
|
260 | public function addPortOperation(DOMElement $portType, $name, $inputMessage = null, $outputMessage = null) |
||
281 | |||
282 | /** |
||
283 | * Add a SOAP operation to an operation element. |
||
284 | * |
||
285 | * @param DOMElement $binding The binding element (from addBindingOperation() method). |
||
286 | * @param string $soapAction SOAP Action. |
||
287 | * @return DOMElement |
||
288 | * @link http://www.w3.org/TR/wsdl#_soap:operation |
||
289 | */ |
||
290 | public function addSoapOperation(DOMElement $binding, $soapAction) |
||
299 | 24 | ||
300 | /** |
||
301 | 24 | * Add a service element to the WSDL. |
|
302 | 24 | * |
|
303 | * @param string $name Service name. |
||
304 | 24 | * @param string $portName Port name. |
|
305 | 24 | * @param string $binding Binding for the port. |
|
306 | * @param string $location SOAP Address location. |
||
307 | 24 | * @return DOMElement |
|
308 | * @link http://www.w3.org/TR/wsdl#_services |
||
309 | 24 | */ |
|
310 | public function addService($name, $portName, $binding, $location) |
||
329 | 9 | ||
330 | 9 | /** |
|
331 | * Add a documentation element to another element in the WSDL. |
||
332 | 9 | * |
|
333 | 9 | * @param DOMElement $inputElement The DOMElement element to add the documentation. |
|
334 | 9 | * @param string $documentation The documentation text. |
|
335 | * @return DOMElement |
||
336 | * @link http://www.w3.org/TR/wsdl#_documentation |
||
337 | */ |
||
338 | 9 | public function addDocumentation(DOMElement $inputElement, $documentation) |
|
358 | 24 | ||
359 | /** |
||
360 | 24 | * Add a complex type. |
|
361 | 21 | * |
|
362 | 15 | * @param string $type The type. |
|
363 | 15 | * @param string $wsdlType The WSDL type. |
|
364 | 6 | */ |
|
365 | 3 | public function addType($type, $wsdlType) |
|
369 | 12 | ||
370 | /** |
||
371 | * Get the XSD Type from a PHP type. |
||
372 | * |
||
373 | * @param string $type The type to get the XSD type from. |
||
374 | * @return string |
||
375 | */ |
||
376 | public function getXSDType($type) |
||
392 | |||
393 | 12 | /** |
|
394 | * Check if a type is a XDS. |
||
395 | 12 | * |
|
396 | * @param string $type The type to check. |
||
397 | * @return boolean |
||
398 | */ |
||
399 | 12 | private function isXDSType($type) |
|
404 | |||
405 | 12 | /** |
|
406 | 12 | * Add a complex type. |
|
407 | * |
||
408 | 12 | * @param string $type Name of the class. |
|
409 | * @return string |
||
410 | 12 | */ |
|
411 | 12 | public function addComplexType($type) |
|
465 | |||
466 | /** |
||
467 | 3 | * Add an array of complex type. |
|
468 | 3 | * |
|
469 | * @param string $singularType The type name without the '[]'. |
||
470 | 3 | * @param string $type The original type name. |
|
471 | 3 | * @return string |
|
472 | */ |
||
473 | 3 | protected function addComplexTypeArray($singularType, $type) |
|
504 | |||
505 | /** |
||
506 | * Parse an xsd:element represented as an array into a DOMElement. |
||
507 | * |
||
508 | * @param array $element An xsd:element represented as an array. |
||
509 | * @return DOMElement |
||
510 | */ |
||
511 | private function parseElement(array $element) |
||
537 | |||
538 | 24 | /** |
|
539 | * Add an xsd:element represented as an array to the schema. |
||
540 | 24 | * |
|
541 | 24 | * @param array $element An xsd:element represented as an array. |
|
542 | * @return string |
||
543 | */ |
||
544 | public function addElement(array $element) |
||
550 | 24 | ||
551 | /** |
||
552 | 24 | * Dump the WSDL as XML string. |
|
553 | 12 | * |
|
554 | 12 | * @return string |
|
555 | */ |
||
556 | 24 | public function dump() |
|
561 | |||
562 | /** |
||
563 | * Convert a PHP type into QName. |
||
564 | * |
||
565 | 6 | * @param string $type The PHP type. |
|
566 | * @return string |
||
567 | 6 | */ |
|
568 | 3 | public static function typeToQName($type) |
|
576 | 6 | ||
577 | 6 | /** |
|
578 | 6 | * Changes the xs:all to an xs:sequence node |
|
579 | 6 | * |
|
580 | * @param \DOMElement $all |
||
581 | * @return \DOMElement |
||
582 | */ |
||
583 | private function changeAllToSequence($all) |
||
599 | |||
600 | } |
||
601 |
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..