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

Envelope::toXML()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP\XML\env_200305;
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\XsNamespace as NS;
14
15
/**
16
 * Class representing a env:Envelope element.
17
 *
18
 * @package simplesaml/xml-soap
19
 */
20
final class Envelope extends AbstractSoapElement
21
{
22
    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_200305\Envelope: $localName, $nodeValue, $namespaceURI, $prefix, $attributes
Loading history...
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
26
27
28
    /**
29
     * Initialize a env:Envelope
30
     *
31
     * @param \SimpleSAML\SOAP\XML\env_200305\Body $body
32
     * @param \SimpleSAML\SOAP\XML\env_200305\Header|null $header
33
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env_200305\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...
34
     */
35
    public function __construct(
36
        protected Body $body,
37
        protected ?Header $header = null,
38
        array $namespacedAttributes = [],
39
    ) {
40
        $this->setAttributesNS($namespacedAttributes);
41
    }
42
43
44
    /**
45
     * @return \SimpleSAML\SOAP\XML\env_200305\Body
46
     */
47
    public function getBody(): Body
48
    {
49
        return $this->body;
50
    }
51
52
53
    /**
54
     * @return \SimpleSAML\SOAP\XML\env_200305\Header|null
55
     */
56
    public function getHeader(): ?Header
57
    {
58
        return $this->header;
59
    }
60
61
62
    /**
63
     * Convert XML into an Envelope element
64
     *
65
     * @param \DOMElement $xml The XML element we should load
66
     * @return static
67
     *
68
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
69
     *   If the qualified name of the supplied element is wrong
70
     */
71
    public static function fromXML(DOMElement $xml): static
72
    {
73
        Assert::same($xml->localName, 'Envelope', InvalidDOMElementException::class);
74
        Assert::same($xml->namespaceURI, Envelope::NS, InvalidDOMElementException::class);
75
76
        $body = Body::getChildrenOfClass($xml);
77
        Assert::count($body, 1, 'Must contain exactly one Body', MissingElementException::class);
78
79
        $header = Header::getChildrenOfClass($xml);
80
        Assert::maxCount($header, 1, 'Cannot process more than one Header element.', TooManyElementsException::class);
81
82
        return new static(
83
            array_pop($body),
84
            empty($header) ? null : array_pop($header),
85
            self::getAttributesNSFromXML($xml),
86
        );
87
    }
88
89
90
    /**
91
     * Convert this Envelope to XML.
92
     *
93
     * @param \DOMElement|null $parent The element we should add this envelope to.
94
     * @return \DOMElement This Envelope-element.
95
     */
96
    public function toXML(DOMElement $parent = null): DOMElement
97
    {
98
        $e = $this->instantiateParentElement($parent);
99
100
        foreach ($this->getAttributesNS() as $attr) {
101
            $attr->toXML($e);
102
        }
103
104
        if ($this->getHeader() !== null && !$this->getHeader()->isEmptyElement()) {
105
            $this->getHeader()->toXML($e);
106
        }
107
108
        $this->getBody()->toXML($e);
109
110
        return $e;
111
    }
112
}
113