Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
91.67% |
44 / 48 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Functions | |
91.67% |
44 / 48 |
|
0.00% |
0 / 1 |
19.21 | |
0.00% |
0 / 1 |
parse | |
91.67% |
44 / 48 |
|
0.00% |
0 / 1 |
19.21 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace WsdlToPhp\PackageGenerator\Parser\SoapClient; |
6 | |
7 | final class Functions extends AbstractParser |
8 | { |
9 | public function parse(): void |
10 | { |
11 | $methods = $this |
12 | ->getGenerator() |
13 | ->getSoapClient() |
14 | ->getSoapClient() |
15 | ->getSoapClient() |
16 | ->__getFunctions() |
17 | ; |
18 | |
19 | $services = $this->getGenerator()->getServices(); |
20 | |
21 | if (!is_array($methods) || 0 === count($methods)) { |
22 | return; |
23 | } |
24 | |
25 | foreach ($methods as $method) { |
26 | $infos = explode(' ', $method); |
27 | // "Regular" SOAP Style |
28 | if (count($infos) < 3) { |
29 | $returnType = $infos[0]; |
30 | if (false !== mb_strpos($infos[1], '()') && array_key_exists(1, $infos)) { |
31 | $methodName = trim(str_replace('()', '', $infos[1])); |
32 | $parameterType = null; |
33 | } else { |
34 | [$methodName, $parameterType] = explode('(', $infos[1]); |
35 | } |
36 | if (!empty($returnType) && !empty($methodName)) { |
37 | $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 | if (0 === mb_stripos($infos[0], 'list(')) { |
46 | $infos = explode(' ', preg_replace('/(list\(.*\)\s)/i', '', $method)); |
47 | array_unshift($infos, 'array'); |
48 | } |
49 | |
50 | /** |
51 | * Returns type is not defined in some case. |
52 | */ |
53 | $start = 0; |
54 | $returnType = false === mb_strpos($infos[0], '(') ? $infos[0] : ''; |
55 | $firstParameterType = ''; |
56 | if (empty($returnType) && false !== mb_strpos($infos[0], '(')) { |
57 | $start = 1; |
58 | [$methodName, $firstParameterType] = explode('(', $infos[0]); |
59 | } elseif (false !== mb_strpos($infos[1], '(')) { |
60 | $start = 2; |
61 | [$methodName, $firstParameterType] = explode('(', $infos[1]); |
62 | } |
63 | if (!empty($methodName)) { |
64 | $methodParameters = []; |
65 | $infosCount = count($infos); |
66 | for ($i = $start; $i < $infosCount; $i += 2) { |
67 | $info = str_replace([ |
68 | ', ', |
69 | ',', |
70 | '(', |
71 | ')', |
72 | '$', |
73 | ], '', trim($infos[$i])); |
74 | if (!empty($info)) { |
75 | $methodParameters = array_merge($methodParameters, [ |
76 | $info => $start === $i ? $firstParameterType : $infos[$i - 1], |
77 | ]); |
78 | } |
79 | } |
80 | $services->addService($this->getGenerator()->getServiceName($methodName), $methodName, $methodParameters, empty($returnType) ? 'unknown' : $returnType); |
81 | } |
82 | } |
83 | } |
84 | } |
85 | } |