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 | 452 | public function parse() |
|
8 | { |
||
9 | 339 | $methods = $this |
|
10 | 452 | ->getGenerator() |
|
11 | 452 | ->getSoapClient() |
|
12 | 452 | ->getSoapClient() |
|
13 | 452 | ->getSoapClient() |
|
14 | 452 | ->__getFunctions(); |
|
15 | 452 | $services = $this->getGenerator()->getServices(); |
|
16 | 452 | if (is_array($methods) && count($methods)) { |
|
17 | 452 | foreach ($methods as $method) { |
|
18 | 452 | $infos = explode(' ', $method); |
|
19 | /** |
||
20 | * "Regular" SOAP Style |
||
21 | */ |
||
22 | 452 | 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 | 48 | } else { |
|
28 | list($methodName, $parameterType) = explode('(', $infos[1]); |
||
29 | } |
||
30 | 64 | if (!empty($returnType) && !empty($methodName)) { |
|
31 | 67 | $services->addService($this->getGenerator(), $this->getGenerator()->getServiceName($methodName), $methodName, $parameterType, $returnType); |
|
32 | 48 | } |
|
33 | 452 | } 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 | 452 | if (stripos($infos[0], 'list(') === 0) { |
|
40 | 20 | $infos = explode(' ', preg_replace('/(list\(.*\)\s)/i', '', $method)); |
|
41 | 20 | array_unshift($infos, 'array'); |
|
42 | 15 | } |
|
43 | /** |
||
44 | * Returns type is not defined in some case |
||
45 | */ |
||
46 | 452 | $start = 0; |
|
47 | 452 | $returnType = strpos($infos[0], '(') === false ? $infos[0] : ''; |
|
48 | 452 | $firstParameterType = ''; |
|
49 | 452 | if (empty($returnType) && strpos($infos[0], '(') !== false) { |
|
50 | $start = 1; |
||
51 | list($methodName, $firstParameterType) = explode('(', $infos[0]); |
||
52 | 452 | } elseif (strpos($infos[1], '(') !== false) { |
|
53 | 452 | $start = 2; |
|
54 | 452 | list($methodName, $firstParameterType) = explode('(', $infos[1]); |
|
55 | 339 | } |
|
56 | 452 | if (!empty($methodName)) { |
|
57 | 452 | $methodParameters = array(); |
|
58 | 452 | $infosCount = count($infos); |
|
59 | 452 | for ($i = $start; $i < $infosCount; $i += 2) { |
|
60 | 452 | $info = str_replace(array( |
|
61 | 452 | ', ', |
|
62 | 339 | ',', |
|
63 | 339 | '(', |
|
64 | 339 | ')', |
|
65 | 339 | '$', |
|
66 | 452 | ), '', trim($infos[$i])); |
|
67 | 452 | if (!empty($info)) { |
|
68 | 452 | $methodParameters = array_merge($methodParameters, array( |
|
69 | 452 | $info => $i == $start ? $firstParameterType : $infos[$i - 1], |
|
70 | 339 | )); |
|
71 | 339 | } |
|
72 | 339 | } |
|
73 | 452 | $services->addService($this->getGenerator(), $this->getGenerator()->getServiceName($methodName), $methodName, $methodParameters, empty($returnType) ? 'unknown' : $returnType); |
|
74 | 339 | } |
|
75 | 339 | } |
|
76 | 339 | } |
|
77 | 339 | } |
|
78 | 452 | } |
|
79 | } |
||
80 |