Conditions | 16 |
Paths | 384 |
Total Lines | 91 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
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 | <? |
||
95 | public function process($request = false, $url = false, $timeout = false, $response = false) { |
||
96 | |||
97 | $result = false; |
||
98 | |||
99 | if ($request instanceof Xml) { |
||
100 | $this->request = $request; |
||
101 | } |
||
102 | |||
103 | if ($url) { |
||
104 | $this->url = $url; |
||
105 | } |
||
106 | |||
107 | if ($timeout) { |
||
108 | $this->timeout = $timeout; |
||
109 | } |
||
110 | |||
111 | if ($response instanceof Xml) { |
||
112 | $this->response = $response; |
||
113 | } |
||
114 | |||
115 | $this->reset(); |
||
116 | |||
117 | if (!$this->request) { |
||
118 | $this->remote_status = 'X502'; |
||
119 | $this->remote_reason = 'No request set'; |
||
120 | } elseif (!$this->request instanceof Xml) { |
||
121 | $this->remote_status = 'X502'; |
||
122 | $this->remote_reason = 'Invalid request set'; |
||
123 | } elseif (!$this->url) { |
||
124 | $this->remote_status = 'X502'; |
||
125 | $this->remote_reason = 'No URL set'; |
||
126 | } elseif (!$this->response instanceof Xml) { |
||
127 | $this->remote_status = 'X502'; |
||
128 | $this->remote_reason = 'Invalid response set'; |
||
129 | } else { |
||
130 | |||
131 | $POSTCh = curl_init(); |
||
132 | |||
133 | curl_setopt($POSTCh, CURLOPT_URL, $this->url); |
||
134 | curl_setopt($POSTCh, CURLOPT_POST, 1 ); |
||
135 | |||
136 | $this->remote_request = '<' . '?xml version="1.0" encoding="UTF-8"' . '?' .'>' . "\n"; |
||
137 | $this->remote_request .= $this->request->getDocument(); |
||
138 | |||
139 | curl_setopt($POSTCh, CURLOPT_POSTFIELDS, $this->remote_request); |
||
140 | curl_setopt($POSTCh, CURLOPT_HTTPHEADER, array('Expect: ') ); |
||
141 | curl_setopt($POSTCh, CURLOPT_RETURNTRANSFER, 1); |
||
142 | curl_setopt($POSTCh, CURLOPT_TIMEOUT, $this->timeout); |
||
143 | |||
144 | if (!$this->verify_host) { |
||
145 | curl_setopt($POSTCh, CURLOPT_SSL_VERIFYHOST, 0); |
||
146 | } |
||
147 | |||
148 | if (!$this->verify_peer) { |
||
149 | curl_setopt($POSTCh, CURLOPT_SSL_VERIFYPEER, false); |
||
150 | } |
||
151 | |||
152 | $POSTResponse = curl_exec($POSTCh); |
||
153 | $POSTErrNo = curl_errno($POSTCh); |
||
154 | $POSTErrStr = curl_error($POSTCh); |
||
155 | $POSTGetInfo = curl_getinfo($POSTCh); |
||
156 | curl_close($POSTCh); |
||
157 | |||
158 | $this->remote_response = $POSTResponse; |
||
159 | |||
160 | if ($POSTErrNo > 0) { |
||
161 | $this->remote_status = 'X502'; |
||
162 | $this->remote_reason = $POSTErrNo . ' - ' . $POSTErrStr; |
||
163 | } elseif ($POSTGetInfo["http_code"] != 200) { |
||
164 | $this->remote_status = 'X' . $POSTGetInfo["http_code"]; |
||
165 | $this->remote_reason = 'HTTP:'. $POSTGetInfo["http_code"]; |
||
166 | } else { |
||
167 | if ($this->response->getRootElement() == '' || strpos($POSTResponse,'<' . $this->response->getRootElement() . '>') !== false) { |
||
168 | if ($this->response->readDocumentFromString($POSTResponse)) { |
||
169 | $this->remote_status = 'P200'; |
||
170 | $this->remote_reason = 'HTTP:'. $POSTGetInfo["http_code"]; |
||
171 | $result = true; |
||
172 | } else { |
||
173 | $this->remote_status = 'X502'; |
||
174 | $this->remote_reason = 'Invalid response - failed to read document'; |
||
175 | } |
||
176 | |||
177 | } else { |
||
178 | $this->remote_status = 'X502'; |
||
179 | $this->remote_reason = 'Invalid response - document not as expected'; |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | return $result; |
||
185 | } |
||
186 | |||
188 |