Passed
Push — master ( c93035...6d9219 )
by Tim
12:59 queued 11:11
created

Envelope::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP\XML\env_200106;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
use SimpleSAML\XML\ExtendableAttributesTrait;
13
use SimpleSAML\XML\ExtendableElementTrait;
14
use SimpleSAML\XML\XsNamespace as NS;
15
16
/**
17
 * Class representing a env:Envelope element.
18
 *
19
 * @package simplesaml/xml-soap
20
 */
21
final class Envelope extends AbstractSoapElement
22
{
23
    use ExtendableElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\SOAP\XML\env_200106\Envelope: $namespaceURI, $localName, $childNodes
Loading history...
24
    use ExtendableAttributesTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\ExtendableAttributesTrait requires some properties which are not provided by SimpleSAML\SOAP\XML\env_200106\Envelope: $localName, $nodeValue, $namespaceURI, $prefix, $attributes
Loading history...
25
26
    /** The namespace-attribute for the xs:any element */
27
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
28
29
    /** The namespace-attribute for the xs:anyAttribute element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * Initialize a env:Envelope
35
     *
36
     * @param \SimpleSAML\SOAP\XML\env_200106\Body $body
37
     * @param \SimpleSAML\SOAP\XML\env_200106\Header|null $header
38
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
39
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env_200106\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
     */
41
    public function __construct(
42
        protected Body $body,
43
        protected ?Header $header = null,
44
        array $children = [],
45
        array $namespacedAttributes = [],
46
    ) {
47
        $this->setElements($children);
48
        $this->setAttributesNS($namespacedAttributes);
49
    }
50
51
52
    /**
53
     * @return \SimpleSAML\SOAP\XML\env_200106\Body
54
     */
55
    public function getBody(): Body
56
    {
57
        return $this->body;
58
    }
59
60
61
    /**
62
     * @return \SimpleSAML\SOAP\XML\env_200106\Header|null
63
     */
64
    public function getHeader(): ?Header
65
    {
66
        return $this->header;
67
    }
68
69
70
    /**
71
     * Convert XML into an Envelope element
72
     *
73
     * @param \DOMElement $xml The XML element we should load
74
     * @return static
75
     *
76
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
77
     *   If the qualified name of the supplied element is wrong
78
     */
79
    public static function fromXML(DOMElement $xml): static
80
    {
81
        Assert::same($xml->localName, 'Envelope', InvalidDOMElementException::class);
82
        Assert::same($xml->namespaceURI, Envelope::NS, InvalidDOMElementException::class);
83
84
        $body = Body::getChildrenOfClass($xml);
85
        Assert::count($body, 1, 'Must contain exactly one Body', MissingElementException::class);
86
87
        $header = Header::getChildrenOfClass($xml);
88
        Assert::maxCount($header, 1, 'Cannot process more than one Header element.', TooManyElementsException::class);
89
90
        return new static(
91
            array_pop($body),
92
            empty($header) ? null : array_pop($header),
93
            self::getChildElementsFromXML($xml),
94
            self::getAttributesNSFromXML($xml),
95
        );
96
    }
97
98
99
    /**
100
     * Convert this Envelope to XML.
101
     *
102
     * @param \DOMElement|null $parent The element we should add this envelope to.
103
     * @return \DOMElement This Envelope-element.
104
     */
105
    public function toXML(DOMElement $parent = null): DOMElement
106
    {
107
        $e = $this->instantiateParentElement($parent);
108
109
        foreach ($this->getAttributesNS() as $attr) {
110
            $attr->toXML($e);
111
        }
112
113
        if ($this->getHeader() !== null && !$this->getHeader()->isEmptyElement()) {
114
            $this->getHeader()->toXML($e);
115
        }
116
117
        $this->getBody()->toXML($e);
118
119
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
120
        foreach ($this->getElements() as $child) {
121
            if (!$child->isEmptyElement()) {
122
                $child->toXML($e);
123
            }
124
        }
125
126
        return $e;
127
    }
128
}
129