| Conditions | 11 | 
| Paths | 14 | 
| Total Lines | 40 | 
| Code Lines | 26 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 132 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | ||
| 18 | public function parse($xmlString, &$isFault) | ||
| 19 |     { | ||
| 20 | $result = xmlrpc_decode($xmlString, 'UTF-8'); | ||
| 21 | |||
| 22 | $isFault = false; | ||
| 23 | |||
| 24 | $toBeVisited = [&$result]; | ||
| 25 |         while (isset($toBeVisited[0]) && $value = &$toBeVisited[0]) { | ||
| 26 | $type = gettype($value); | ||
| 27 |             if ($type === 'object') { | ||
| 28 |                 $xmlRpcType = $value->{'xmlrpc_type'}; | ||
| 29 |                 if ($xmlRpcType === 'datetime') { | ||
| 30 | $value = \DateTime::createFromFormat( | ||
| 31 | 'Ymd\TH:i:s', | ||
| 32 | $value->scalar, | ||
| 33 |                         isset($timezone) ? $timezone : $timezone = new \DateTimeZone('UTC') | ||
| 34 | ); | ||
| 35 |                 } elseif ($xmlRpcType === 'base64') { | ||
| 36 |                     if ($value->scalar !== '') { | ||
| 37 | $value = Base64Value::serialize($value->scalar); | ||
| 38 |                     } else { | ||
| 39 | $value = null; | ||
| 40 | } | ||
| 41 | } | ||
| 42 |             } elseif ($type === 'array') { | ||
| 43 |                 foreach ($value as &$element) { | ||
| 44 | $toBeVisited[] = &$element; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | array_shift($toBeVisited); | ||
| 49 | } | ||
| 50 | |||
| 51 |         if (is_array($result)) { | ||
| 52 | reset($result); | ||
| 53 | $isFault = xmlrpc_is_fault($result); | ||
| 54 | } | ||
| 55 | |||
| 56 | return $result; | ||
| 57 | } | ||
| 58 | } | ||
| 59 |