Completed
Push — master ( ab3100...ab2db9 )
by Mikaël
57:47 queued 20:08
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 324
    public function parse()
8
    {
9 324
        $methods = $this->getGenerator()
10 324
            ->getSoapClient()
11 324
            ->getSoapClient()
12 324
            ->getSoapClient()
13 324
            ->__getFunctions();
14 324
        $services = $this->getGenerator()->getServices();
15 324
        if (is_array($methods) && count($methods)) {
16 324
            foreach ($methods as $method) {
17 324
                $infos = explode(' ', $method);
18
                /**
19
                 * "Regular" SOAP Style
20
                 */
21 324
                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 324
                } 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 324
                    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 324
                    $start = 0;
46 324
                    $returnType = strpos($infos[0], '(') === false ? $infos[0] : '';
47 324
                    $firstParameterType = '';
48 324
                    if (empty($returnType) && strpos($infos[0], '(') !== false) {
49
                        $start = 1;
50
                        list($methodName, $firstParameterType) = explode('(', $infos[0]);
51 324
                    } elseif (strpos($infos[1], '(') !== false) {
52 324
                        $start = 2;
53 324
                        list($methodName, $firstParameterType) = explode('(', $infos[1]);
54 162
                    }
55 324
                    if (!empty($methodName)) {
56 324
                        $methodParameters = [];
57 324
                        $infosCount = count($infos);
58 324
                        for ($i = $start; $i < $infosCount; $i += 2) {
59 324
                            $info = str_replace([
60 324
                                ', ',
61 162
                                ',',
62 162
                                '(',
63 162
                                ')',
64 162
                                '$',
65 324
                            ], '', trim($infos[$i]));
66 324
                            if (!empty($info)) {
67 324
                                $methodParameters = array_merge($methodParameters, [
68 324
                                    $info => $i == $start ? $firstParameterType : $infos[$i - 1],
69 162
                                ]);
70 162
                            }
71 162
                        }
72 324
                        $services->addService($this->getGenerator()->getServiceName($methodName), $methodName, $methodParameters, empty($returnType) ? 'unknown' : $returnType);
73 162
                    }
74 162
                }
75 162
            }
76 162
        }
77 324
    }
78
}
79