Envelope   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 3 1
A getHeader() 0 3 1
A fromXML() 0 16 2
A __construct() 0 8 1
A toXML() 0 22 6
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\SchemaValidatableElementInterface;
15
use SimpleSAML\XML\SchemaValidatableElementTrait;
16
use SimpleSAML\XML\XsNamespace as NS;
17
18
/**
19
 * Class representing a env:Envelope element.
20
 *
21
 * @package simplesaml/xml-soap
22
 */
23
final class Envelope extends AbstractSoapElement implements SchemaValidatableElementInterface
24
{
25
    use ExtendableElementTrait;
26
    use ExtendableAttributesTrait;
27
    use SchemaValidatableElementTrait;
28
29
    /** The namespace-attribute for the xs:any element */
30
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
31
32
    /** The namespace-attribute for the xs:anyAttribute element */
33
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
34
35
36
    /**
37
     * Initialize a env:Envelope
38
     *
39
     * @param \SimpleSAML\SOAP\XML\env_200106\Body $body
40
     * @param \SimpleSAML\SOAP\XML\env_200106\Header|null $header
41
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
42
     * @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...
43
     */
44
    public function __construct(
45
        protected Body $body,
46
        protected ?Header $header = null,
47
        array $children = [],
48
        array $namespacedAttributes = [],
49
    ) {
50
        $this->setElements($children);
51
        $this->setAttributesNS($namespacedAttributes);
52
    }
53
54
55
    /**
56
     * @return \SimpleSAML\SOAP\XML\env_200106\Body
57
     */
58
    public function getBody(): Body
59
    {
60
        return $this->body;
61
    }
62
63
64
    /**
65
     * @return \SimpleSAML\SOAP\XML\env_200106\Header|null
66
     */
67
    public function getHeader(): ?Header
68
    {
69
        return $this->header;
70
    }
71
72
73
    /**
74
     * Convert XML into an Envelope element
75
     *
76
     * @param \DOMElement $xml The XML element we should load
77
     * @return static
78
     *
79
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
80
     *   If the qualified name of the supplied element is wrong
81
     */
82
    public static function fromXML(DOMElement $xml): static
83
    {
84
        Assert::same($xml->localName, 'Envelope', InvalidDOMElementException::class);
85
        Assert::same($xml->namespaceURI, Envelope::NS, InvalidDOMElementException::class);
86
87
        $body = Body::getChildrenOfClass($xml);
88
        Assert::count($body, 1, 'Must contain exactly one Body', MissingElementException::class);
89
90
        $header = Header::getChildrenOfClass($xml);
91
        Assert::maxCount($header, 1, 'Cannot process more than one Header element.', TooManyElementsException::class);
92
93
        return new static(
94
            array_pop($body),
95
            empty($header) ? null : array_pop($header),
96
            self::getChildElementsFromXML($xml),
97
            self::getAttributesNSFromXML($xml),
98
        );
99
    }
100
101
102
    /**
103
     * Convert this Envelope to XML.
104
     *
105
     * @param \DOMElement|null $parent The element we should add this envelope to.
106
     * @return \DOMElement This Envelope-element.
107
     */
108
    public function toXML(?DOMElement $parent = null): DOMElement
109
    {
110
        $e = $this->instantiateParentElement($parent);
111
112
        foreach ($this->getAttributesNS() as $attr) {
113
            $attr->toXML($e);
114
        }
115
116
        if ($this->getHeader() !== null && !$this->getHeader()->isEmptyElement()) {
117
            $this->getHeader()->toXML($e);
118
        }
119
120
        $this->getBody()->toXML($e);
121
122
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
123
        foreach ($this->getElements() as $child) {
124
            if (!$child->isEmptyElement()) {
125
                $child->toXML($e);
126
            }
127
        }
128
129
        return $e;
130
    }
131
}
132