Completed
Push — 2.x ( 043669...4fa139 )
by Mikaël
65:52 queued 32:03
created

Functions   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 94.83%

Importance

Changes 0
Metric Value
wmc 21
lcom 0
cbo 5
dl 0
loc 74
ccs 55
cts 58
cp 0.9483
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 71 21
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Parser\SoapClient;
4
5
class Functions extends AbstractParser
6
{
7 460
    public function parse()
8
    {
9 460
        $methods = $this->getGenerator()
10 460
            ->getSoapClient()
11 460
            ->getSoapClient()
12 460
            ->getSoapClient()
13 460
            ->__getFunctions();
14 460
        $services = $this->getGenerator()->getServices();
15 460
        if (is_array($methods) && count($methods)) {
16 460
            foreach ($methods as $method) {
17 460
                $infos = explode(' ', $method);
18
                /**
19
                 * "Regular" SOAP Style
20
                 */
21 460
                if (count($infos) < 3) {
22 64
                    $returnType = $infos[0];
23 64
                    if (count($infos) < 3 && strpos($infos[1], '()') !== false && array_key_exists(1, $infos)) {
24 64
                        $methodName = trim(str_replace('()', '', $infos[1]));
25 64
                        $parameterType = null;
26 48
                    } else {
27
                        list($methodName, $parameterType) = explode('(', $infos[1]);
28
                    }
29 64
                    if (!empty($returnType) && !empty($methodName)) {
30 64
                        $services->addService($this->getGenerator(), $this->getGenerator()->getServiceName($methodName), $methodName, $parameterType, $returnType);
31 51
                    }
32 460
                } 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 460
                    if (stripos($infos[0], 'list(') === 0) {
39 20
                        $infos = explode(' ', preg_replace('/(list\(.*\)\s)/i', '', $method));
40 20
                        array_unshift($infos, 'array');
41 15
                    }
42
                    /**
43
                     * Returns type is not defined in some case
44
                     */
45 460
                    $start = 0;
46 460
                    $returnType = strpos($infos[0], '(') === false ? $infos[0] : '';
47 460
                    $firstParameterType = '';
48 460
                    if (empty($returnType) && strpos($infos[0], '(') !== false) {
49
                        $start = 1;
50
                        list($methodName, $firstParameterType) = explode('(', $infos[0]);
51 460
                    } elseif (strpos($infos[1], '(') !== false) {
52 460
                        $start = 2;
53 460
                        list($methodName, $firstParameterType) = explode('(', $infos[1]);
54 345
                    }
55 460
                    if (!empty($methodName)) {
56 460
                        $methodParameters = array();
57 460
                        $infosCount = count($infos);
58 460
                        for ($i = $start; $i < $infosCount; $i += 2) {
59 460
                            $info = str_replace(array(
60 460
                                ', ',
61 345
                                ',',
62 345
                                '(',
63 345
                                ')',
64 345
                                '$',
65 460
                            ), '', trim($infos[$i]));
66 460
                            if (!empty($info)) {
67 460
                                $methodParameters = array_merge($methodParameters, array(
68 460
                                    $info => $i == $start ? $firstParameterType : $infos[$i - 1],
69 345
                                ));
70 345
                            }
71 345
                        }
72 460
                        $services->addService($this->getGenerator(), $this->getGenerator()->getServiceName($methodName), $methodName, $methodParameters, empty($returnType) ? 'unknown' : $returnType);
73 345
                    }
74 345
                }
75 345
            }
76 345
        }
77 460
    }
78
}
79