| Conditions | 10 |
| Paths | 128 |
| Total Lines | 72 |
| Code Lines | 37 |
| Lines | 9 |
| Ratio | 12.5 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 52 | public function query() { |
||
| 53 | $args = func_get_args(); |
||
| 54 | $method = array_shift($args); |
||
| 55 | $request = new IXR_Request($method, $args); |
||
| 56 | $xml = $request->getXml(); |
||
| 57 | |||
| 58 | $port = $this->port ? ":$this->port" : ''; |
||
| 59 | $url = $this->scheme . '://' . $this->server . $port . $this->path; |
||
| 60 | $args = array( |
||
| 61 | 'headers' => array('Content-Type' => 'text/xml'), |
||
| 62 | 'user-agent' => $this->useragent, |
||
| 63 | 'body' => $xml, |
||
| 64 | ); |
||
| 65 | |||
| 66 | // Merge Custom headers ala #8145 |
||
| 67 | foreach ( $this->headers as $header => $value ) { |
||
| 68 | $args['headers'][$header] = $value; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Filters the headers collection to be sent to the XML-RPC server. |
||
| 73 | * |
||
| 74 | * @since 4.4.0 |
||
| 75 | * |
||
| 76 | * @param array $headers Array of headers to be sent. |
||
| 77 | */ |
||
| 78 | $args['headers'] = apply_filters( 'wp_http_ixr_client_headers', $args['headers'] ); |
||
| 79 | |||
| 80 | if ( $this->timeout !== false ) { |
||
| 81 | $args['timeout'] = $this->timeout; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Now send the request |
||
| 85 | if ( $this->debug ) { |
||
| 86 | echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; |
||
| 87 | } |
||
| 88 | |||
| 89 | $response = wp_remote_post($url, $args); |
||
| 90 | |||
| 91 | if ( is_wp_error($response) ) { |
||
| 92 | $errno = $response->get_error_code(); |
||
| 93 | $errorstr = $response->get_error_message(); |
||
| 94 | $this->error = new IXR_Error(-32300, "transport error: $errno $errorstr"); |
||
| 95 | return false; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ( 200 != wp_remote_retrieve_response_code( $response ) ) { |
||
| 99 | $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')'); |
||
| 100 | return false; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ( $this->debug ) { |
||
| 104 | echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n"; |
||
| 105 | } |
||
| 106 | |||
| 107 | // Now parse what we've got back |
||
| 108 | $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) ); |
||
|
|
|||
| 109 | View Code Duplication | if ( ! $this->message->parse() ) { |
|
| 110 | // XML error |
||
| 111 | $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | |||
| 115 | // Is the message a fault? |
||
| 116 | View Code Duplication | if ( $this->message->messageType == 'fault' ) { |
|
| 117 | $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
||
| 118 | return false; |
||
| 119 | } |
||
| 120 | |||
| 121 | // Message must be OK |
||
| 122 | return true; |
||
| 123 | } |
||
| 124 | } |
||
| 125 |
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..