| Conditions | 49 |
| Paths | 136 |
| Total Lines | 173 |
| Code Lines | 108 |
| Lines | 36 |
| Ratio | 20.81 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 224 | public function xmlrpc_ee($parser, $name, $rebuildXmlrpcvals = true) |
||
| 225 | { |
||
| 226 | if ($this->_xh['isf'] < 2) { |
||
| 227 | // push this element name from stack |
||
| 228 | // NB: if XML validates, correct opening/closing is guaranteed and |
||
| 229 | // we do not have to check for $name == $currElem. |
||
| 230 | // we also checked for proper nesting at start of elements... |
||
| 231 | $currElem = array_pop($this->_xh['stack']); |
||
| 232 | |||
| 233 | switch ($name) { |
||
| 234 | case 'VALUE': |
||
| 235 | // This if() detects if no scalar was inside <VALUE></VALUE> |
||
| 236 | if ($this->_xh['vt'] == 'value') { |
||
| 237 | $this->_xh['value'] = $this->_xh['ac']; |
||
| 238 | $this->_xh['vt'] = Value::$xmlrpcString; |
||
| 239 | } |
||
| 240 | |||
| 241 | if ($rebuildXmlrpcvals) { |
||
| 242 | // build the xmlrpc val out of the data received, and substitute it |
||
| 243 | $temp = new Value($this->_xh['value'], $this->_xh['vt']); |
||
| 244 | // in case we got info about underlying php class, save it |
||
| 245 | // in the object we're rebuilding |
||
| 246 | if (isset($this->_xh['php_class'])) { |
||
| 247 | $temp->_php_class = $this->_xh['php_class']; |
||
| 248 | } |
||
| 249 | // check if we are inside an array or struct: |
||
| 250 | // if value just built is inside an array, let's move it into array on the stack |
||
| 251 | $vscount = count($this->_xh['valuestack']); |
||
| 252 | View Code Duplication | if ($vscount && $this->_xh['valuestack'][$vscount - 1]['type'] == 'ARRAY') { |
|
| 253 | $this->_xh['valuestack'][$vscount - 1]['values'][] = $temp; |
||
| 254 | } else { |
||
| 255 | $this->_xh['value'] = $temp; |
||
| 256 | } |
||
| 257 | } else { |
||
| 258 | /// @todo this needs to treat correctly php-serialized objects, |
||
| 259 | /// since std deserializing is done by php_xmlrpc_decode, |
||
| 260 | /// which we will not be calling... |
||
| 261 | if (isset($this->_xh['php_class'])) { |
||
| 262 | } |
||
| 263 | |||
| 264 | // check if we are inside an array or struct: |
||
| 265 | // if value just built is inside an array, let's move it into array on the stack |
||
| 266 | $vscount = count($this->_xh['valuestack']); |
||
| 267 | View Code Duplication | if ($vscount && $this->_xh['valuestack'][$vscount - 1]['type'] == 'ARRAY') { |
|
| 268 | $this->_xh['valuestack'][$vscount - 1]['values'][] = $this->_xh['value']; |
||
| 269 | } |
||
| 270 | } |
||
| 271 | break; |
||
| 272 | case 'BOOLEAN': |
||
| 273 | case 'I4': |
||
| 274 | case 'I8': |
||
| 275 | case 'EX:I8': |
||
| 276 | case 'INT': |
||
| 277 | case 'STRING': |
||
| 278 | case 'DOUBLE': |
||
| 279 | case 'DATETIME.ISO8601': |
||
| 280 | case 'BASE64': |
||
| 281 | $this->_xh['vt'] = strtolower($name); |
||
| 282 | /// @todo: optimization creep - remove the if/elseif cycle below |
||
| 283 | /// since the case() in which we are already did that |
||
| 284 | if ($name == 'STRING') { |
||
| 285 | $this->_xh['value'] = $this->_xh['ac']; |
||
| 286 | View Code Duplication | } elseif ($name == 'DATETIME.ISO8601') { |
|
| 287 | if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $this->_xh['ac'])) { |
||
| 288 | error_log('XML-RPC: ' . __METHOD__ . ': invalid value received in DATETIME: ' . $this->_xh['ac']); |
||
| 289 | } |
||
| 290 | $this->_xh['vt'] = Value::$xmlrpcDateTime; |
||
| 291 | $this->_xh['value'] = $this->_xh['ac']; |
||
| 292 | } elseif ($name == 'BASE64') { |
||
| 293 | /// @todo check for failure of base64 decoding / catch warnings |
||
| 294 | $this->_xh['value'] = base64_decode($this->_xh['ac']); |
||
| 295 | } elseif ($name == 'BOOLEAN') { |
||
| 296 | // special case here: we translate boolean 1 or 0 into PHP |
||
| 297 | // constants true or false. |
||
| 298 | // Strings 'true' and 'false' are accepted, even though the |
||
| 299 | // spec never mentions them (see eg. Blogger api docs) |
||
| 300 | // NB: this simple checks helps a lot sanitizing input, ie no |
||
| 301 | // security problems around here |
||
| 302 | if ($this->_xh['ac'] == '1' || strcasecmp($this->_xh['ac'], 'true') == 0) { |
||
| 303 | $this->_xh['value'] = true; |
||
| 304 | } else { |
||
| 305 | // log if receiving something strange, even though we set the value to false anyway |
||
| 306 | if ($this->_xh['ac'] != '0' && strcasecmp($this->_xh['ac'], 'false') != 0) { |
||
| 307 | error_log('XML-RPC: ' . __METHOD__ . ': invalid value received in BOOLEAN: ' . $this->_xh['ac']); |
||
| 308 | } |
||
| 309 | $this->_xh['value'] = false; |
||
| 310 | } |
||
| 311 | View Code Duplication | } elseif ($name == 'DOUBLE') { |
|
| 312 | // we have a DOUBLE |
||
| 313 | // we must check that only 0123456789-.<space> are characters here |
||
| 314 | // NOTE: regexp could be much stricter than this... |
||
| 315 | if (!preg_match('/^[+-eE0123456789 \t.]+$/', $this->_xh['ac'])) { |
||
| 316 | /// @todo: find a better way of throwing an error than this! |
||
| 317 | error_log('XML-RPC: ' . __METHOD__ . ': non numeric value received in DOUBLE: ' . $this->_xh['ac']); |
||
| 318 | $this->_xh['value'] = 'ERROR_NON_NUMERIC_FOUND'; |
||
| 319 | } else { |
||
| 320 | // it's ok, add it on |
||
| 321 | $this->_xh['value'] = (double)$this->_xh['ac']; |
||
| 322 | } |
||
| 323 | } else { |
||
| 324 | // we have an I4/I8/INT |
||
| 325 | // we must check that only 0123456789-<space> are characters here |
||
| 326 | View Code Duplication | if (!preg_match('/^[+-]?[0123456789 \t]+$/', $this->_xh['ac'])) { |
|
| 327 | /// @todo find a better way of throwing an error than this! |
||
| 328 | error_log('XML-RPC: ' . __METHOD__ . ': non numeric value received in INT: ' . $this->_xh['ac']); |
||
| 329 | $this->_xh['value'] = 'ERROR_NON_NUMERIC_FOUND'; |
||
| 330 | } else { |
||
| 331 | // it's ok, add it on |
||
| 332 | $this->_xh['value'] = (int)$this->_xh['ac']; |
||
| 333 | } |
||
| 334 | } |
||
| 335 | $this->_xh['lv'] = 3; // indicate we've found a value |
||
| 336 | break; |
||
| 337 | case 'NAME': |
||
| 338 | $this->_xh['valuestack'][count($this->_xh['valuestack']) - 1]['name'] = $this->_xh['ac']; |
||
| 339 | break; |
||
| 340 | case 'MEMBER': |
||
| 341 | // add to array in the stack the last element built, |
||
| 342 | // unless no VALUE was found |
||
| 343 | if ($this->_xh['vt']) { |
||
| 344 | $vscount = count($this->_xh['valuestack']); |
||
| 345 | $this->_xh['valuestack'][$vscount - 1]['values'][$this->_xh['valuestack'][$vscount - 1]['name']] = $this->_xh['value']; |
||
| 346 | } else { |
||
| 347 | error_log('XML-RPC: ' . __METHOD__ . ': missing VALUE inside STRUCT in received xml'); |
||
| 348 | } |
||
| 349 | break; |
||
| 350 | case 'DATA': |
||
| 351 | $this->_xh['vt'] = null; // reset this to check for 2 data elements in a row - even if they're empty |
||
| 352 | break; |
||
| 353 | case 'STRUCT': |
||
| 354 | case 'ARRAY': |
||
| 355 | // fetch out of stack array of values, and promote it to current value |
||
| 356 | $currVal = array_pop($this->_xh['valuestack']); |
||
| 357 | $this->_xh['value'] = $currVal['values']; |
||
| 358 | $this->_xh['vt'] = strtolower($name); |
||
| 359 | if (isset($currVal['php_class'])) { |
||
| 360 | $this->_xh['php_class'] = $currVal['php_class']; |
||
| 361 | } |
||
| 362 | break; |
||
| 363 | case 'PARAM': |
||
| 364 | // add to array of params the current value, |
||
| 365 | // unless no VALUE was found |
||
| 366 | if ($this->_xh['vt']) { |
||
| 367 | $this->_xh['params'][] = $this->_xh['value']; |
||
| 368 | $this->_xh['pt'][] = $this->_xh['vt']; |
||
| 369 | } else { |
||
| 370 | error_log('XML-RPC: ' . __METHOD__ . ': missing VALUE inside PARAM in received xml'); |
||
| 371 | } |
||
| 372 | break; |
||
| 373 | case 'METHODNAME': |
||
| 374 | $this->_xh['method'] = preg_replace('/^[\n\r\t ]+/', '', $this->_xh['ac']); |
||
| 375 | break; |
||
| 376 | case 'NIL': |
||
| 377 | case 'EX:NIL': |
||
| 378 | if (PhpXmlRpc::$xmlrpc_null_extension) { |
||
| 379 | $this->_xh['vt'] = 'null'; |
||
| 380 | $this->_xh['value'] = null; |
||
| 381 | $this->_xh['lv'] = 3; |
||
| 382 | break; |
||
| 383 | } |
||
| 384 | // drop through intentionally if nil extension not enabled |
||
| 385 | case 'PARAMS': |
||
| 386 | case 'FAULT': |
||
| 387 | case 'METHODCALL': |
||
| 388 | case 'METHORESPONSE': |
||
| 389 | break; |
||
| 390 | default: |
||
| 391 | // End of INVALID ELEMENT! |
||
| 392 | // shall we add an assert here for unreachable code??? |
||
| 393 | break; |
||
| 394 | } |
||
| 395 | } |
||
| 396 | } |
||
| 397 | |||
| 562 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.