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

Functions   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
eloc 47
c 0
b 0
f 0
dl 0
loc 68
ccs 39
cts 42
cp 0.9286
rs 10
wmc 21

1 Method

Rating   Name   Duplication   Size   Complexity  
D parse() 0 66 21
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