Passed
Push — feature/issue-246 ( 79981d )
by Mikaël
14:50
created

Functions::parse()   D

Complexity

Conditions 21
Paths 55

Size

Total Lines 66
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 39
CRAP Score 21.1605

Importance

Changes 0
Metric Value
cc 21
eloc 46
c 0
b 0
f 0
nc 55
nop 0
dl 0
loc 66
ccs 39
cts 42
cp 0.9286
crap 21.1605
rs 4.1666

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