XMLRpcStyle::generateParameters()   B
last analyzed

Complexity

Conditions 6
Paths 12

Size

Total Lines 46

Duplication

Lines 26
Ratio 56.52 %

Code Coverage

Tests 41
CRAP Score 6

Importance

Changes 0
Metric Value
dl 26
loc 46
ccs 41
cts 41
cp 1
rs 8.5559
c 0
b 0
f 0
cc 6
nc 12
nop 4
crap 6
1
<?php
2
/**
3
 * Copyright (C) 2013-2020
4
 * Piotr Olaszewski <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
namespace WSDL\XML\XMLStyle;
25
26
use DOMDocument;
27
use DOMElement;
28
use WSDL\Parser\Node;
29
use WSDL\XML\XMLAttributeHelper;
30
31
/**
32
 * XMLRpcStyle
33
 *
34
 * @author Piotr Olaszewski <[email protected]>
35
 */
36
class XMLRpcStyle implements XMLStyle
37
{
38 View Code Duplication
    public function generateBinding(DOMDocument $DOMDocument, string $soapVersion): DOMElement
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        return XMLAttributeHelper::forDOM($DOMDocument)
41 2
            ->createElementWithAttributes($soapVersion . ':binding', [
42
                'style' => 'rpc', 'transport' => 'http://schemas.xmlsoap.org/soap/http'
43 2
            ]);
44 2
    }
45 2
46 2
    /**
47
     * @inheritdoc
48
     */
49
    public function generateMessagePart(DOMDocument $DOMDocument, array $nodes): array
50
    {
51
        $parts = [];
52 2
        foreach ($nodes as $node) {
53
            $attributes = $this->attributes($node);
54 2
            $parts[] = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('part', $attributes);
55 2
        }
56 2
57 2
        return $parts;
58 2
    }
59 2
60
    /**
61
     * @inheritdoc
62
     */
63
    public function generateTypes(DOMDocument $DOMDocument, array $parameters, string $soapVersion): array
64
    {
65 6
        $types = [];
66
        foreach ($parameters as $parameter) {
67 6
            $node = $parameter->getNode();
68 6
            $nodeGen = $this->generateParameters($DOMDocument, $node, null, $soapVersion);
69 6
            $types = array_merge($types, $nodeGen);
70 6
        }
71 6
72 6
        return $types;
73 6
    }
74
75
    /**
76
     * @param DOMDocument $DOMDocument
77
     * @param Node $node
78
     * @param DOMElement|null $sequenceElement
79
     * @param string $soapVersion
80
     * @return DOMElement[]
81
     */
82
    private function generateParameters(DOMDocument $DOMDocument, Node $node, DOMElement $sequenceElement = null, string $soapVersion): array
83 6
    {
84
        $result = [];
85 6 View Code Duplication
        if ($sequenceElement) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86 6
            $attributes = $this->attributes($node);
87 5
            $elementPartElement = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', $attributes);
88 5
            $sequenceElement->appendChild($elementPartElement);
89 5
        }
90 5 View Code Duplication
        if ($node->isArray()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91 6
            $complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument)
92 4
                ->createElementWithAttributes('xsd:complexType', ['name' => $node->getNameForArray()]);
93 4
            $complexContentElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:complexContent');
94 4
            $restrictionElement = XMLAttributeHelper::forDOM($DOMDocument)
95 4
                ->createElementWithAttributes('xsd:restriction', ['base' => 'soapenc:Array']);
96 4
            $type = $node->isObject() ? 'ns:' . $node->getNameForObject() . '[]' : 'xsd:' . $node->getType() . '[]';
97 4
            $attributeElement = XMLAttributeHelper::forDOM($DOMDocument)
98 4
                ->createElementWithAttributes('xsd:attribute', [
99 4
                    'ref' => 'soapenc:arrayType',
100 4
                    $soapVersion . ':arrayType' => $type
101 4
                ]);
102 4
            $restrictionElement->appendChild($attributeElement);
103 4
            $complexContentElement->appendChild($restrictionElement);
104 4
            $complexTypeElement->appendChild($complexContentElement);
105 4
            $result[] = $complexTypeElement;
106 4
        }
107 4
        if ($node->isObject()) {
108 6
            $name = $node->getNameForObject();
109 5
            $element = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', [
110 5
                'name' => $name, 'nillable' => 'true', 'type' => 'ns:' . $name
111 5
            ]);
112 5
            $result[] = $element;
113 5
114
            $complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument)
115 5
                ->createElementWithAttributes('xsd:complexType', ['name' => $node->getNameForObject()]);
116 5
            $sequenceElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:sequence');
117 5
            $complexTypeElement->appendChild($sequenceElement);
118 5
119
            $result[] = $complexTypeElement;
120 5 View Code Duplication
            foreach ($node->getElements() as $nodeElement) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121 5
                $tmp = $this->generateParameters($DOMDocument, $nodeElement, $sequenceElement, $soapVersion);
122 5
                $result = array_merge($result, $tmp);
123 5
            }
124 5
        }
125 5
126 6
        return $result;
127
    }
128
129 View Code Duplication
    private function attributes(Node $node): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        if ($node->isArray()) {
132
            $attributes = ['name' => $node->getSanitizedName(), 'type' => 'ns:' . $node->getNameForArray()];
133 6
        } elseif ($node->isObject()) {
134
            $attributes = ['name' => $node->getSanitizedName(), 'element' => 'ns:' . $node->getNameForObject()];
135 6
        } else {
136 3
            $attributes = ['name' => $node->getSanitizedName(), 'type' => 'xsd:' . $node->getType()];
137 6
        }
138 3
139 3
        return $attributes;
140 5
    }
141
}
142