Completed
Push — 1.x ( 257780...f31d1d )
by Mikaël
42:33 queued 33:38
created

Functions::parse()   C

Complexity

Conditions 21
Paths 55

Size

Total Lines 72
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 56
CRAP Score 21.0578

Importance

Changes 0
Metric Value
dl 0
loc 72
ccs 56
cts 59
cp 0.9492
rs 5.4212
c 0
b 0
f 0
cc 21
eloc 48
nc 55
nop 0
crap 21.0578

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Parser\SoapClient;
4
5
class Functions extends AbstractParser
6
{
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