| Conditions | 21 |
| Paths | 55 |
| Total Lines | 72 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 56 |
| CRAP Score | 21.0578 |
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 |
||
| 7 | 460 | public function parse() |
|
| 8 | { |
||
| 9 | 460 | $methods = $this |
|
| 10 | 460 | ->getGenerator() |
|
| 11 | 460 | ->getSoapClient() |
|
| 12 | 460 | ->getSoapClient() |
|
| 13 | 460 | ->getSoapClient() |
|
| 14 | 460 | ->__getFunctions(); |
|
| 15 | 460 | $services = $this->getGenerator()->getServices(); |
|
| 16 | 460 | if (is_array($methods) && count($methods)) { |
|
| 17 | 460 | foreach ($methods as $method) { |
|
| 18 | 460 | $infos = explode(' ', $method); |
|
| 19 | /** |
||
| 20 | * "Regular" SOAP Style |
||
| 21 | */ |
||
| 22 | 460 | if (count($infos) < 3) { |
|
| 23 | 64 | $returnType = $infos[0]; |
|
| 24 | 64 | if (count($infos) < 3 && strpos($infos[1], '()') !== false && array_key_exists(1, $infos)) { |
|
| 25 | 64 | $methodName = trim(str_replace('()', '', $infos[1])); |
|
| 26 | 64 | $parameterType = null; |
|
| 27 | 64 | } else { |
|
| 28 | list($methodName, $parameterType) = explode('(', $infos[1]); |
||
| 29 | } |
||
| 30 | 64 | if (!empty($returnType) && !empty($methodName)) { |
|
| 31 | 68 | $services->addService($this->getGenerator(), $this->getGenerator()->getServiceName($methodName), $methodName, $parameterType, $returnType); |
|
| 32 | 64 | } |
|
| 33 | 460 | } elseif (count($infos) >= 3) { |
|
| 34 | /** |
||
| 35 | * RPC SOAP Style |
||
| 36 | * Some RPC WS defines the return type as a list of values |
||
| 37 | * So we define the return type as an array and reset the informations to use to extract method name and parameters |
||
| 38 | */ |
||
| 39 | 460 | if (stripos($infos[0], 'list(') === 0) { |
|
| 40 | 20 | $infos = explode(' ', preg_replace('/(list\(.*\)\s)/i', '', $method)); |
|
| 41 | 20 | array_unshift($infos, 'array'); |
|
| 42 | 20 | } |
|
| 43 | /** |
||
| 44 | * Returns type is not defined in some case |
||
| 45 | */ |
||
| 46 | 460 | $start = 0; |
|
| 47 | 460 | $returnType = strpos($infos[0], '(') === false ? $infos[0] : ''; |
|
| 48 | 460 | $firstParameterType = ''; |
|
| 49 | 460 | if (empty($returnType) && strpos($infos[0], '(') !== false) { |
|
| 50 | $start = 1; |
||
| 51 | list($methodName, $firstParameterType) = explode('(', $infos[0]); |
||
| 52 | 460 | } elseif (strpos($infos[1], '(') !== false) { |
|
| 53 | 460 | $start = 2; |
|
| 54 | 460 | list($methodName, $firstParameterType) = explode('(', $infos[1]); |
|
| 55 | 460 | } |
|
| 56 | 460 | if (!empty($methodName)) { |
|
| 57 | 460 | $methodParameters = array(); |
|
| 58 | 460 | $infosCount = count($infos); |
|
| 59 | 460 | for ($i = $start; $i < $infosCount; $i += 2) { |
|
| 60 | 460 | $info = str_replace(array( |
|
| 61 | 460 | ', ', |
|
| 62 | 460 | ',', |
|
| 63 | 460 | '(', |
|
| 64 | 460 | ')', |
|
| 65 | 460 | '$', |
|
| 66 | 460 | ), '', trim($infos[$i])); |
|
| 67 | 460 | if (!empty($info)) { |
|
| 68 | 460 | $methodParameters = array_merge($methodParameters, array( |
|
| 69 | 460 | $info => $i == $start ? $firstParameterType : $infos[$i - 1], |
|
| 70 | 460 | )); |
|
| 71 | 460 | } |
|
| 72 | 460 | } |
|
| 73 | 460 | $services->addService($this->getGenerator(), $this->getGenerator()->getServiceName($methodName), $methodName, $methodParameters, empty($returnType) ? 'unknown' : $returnType); |
|
| 74 | 460 | } |
|
| 75 | 460 | } |
|
| 76 | 460 | } |
|
| 77 | 460 | } |
|
| 78 | 460 | } |
|
| 79 | } |
||
| 80 |