Completed
Push — feature/issue-157 ( 29a959...1c3d5c )
by Mikaël
27:13 queued 01:48
created

Functions   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 94.34%

Importance

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