Passed
Push — develop ( e6f84d...350782 )
by Mikaël
09:01 queued 28s
created

Functions::parse()   D

Complexity

Conditions 19
Paths 54

Size

Total Lines 71
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 38
CRAP Score 19.3114

Importance

Changes 0
Metric Value
cc 19
eloc 48
nc 54
nop 0
dl 0
loc 71
ccs 38
cts 42
cp 0.9048
crap 19.3114
rs 4.5166
c 0
b 0
f 0

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