Issues (16)

src/SOAP12/XML/Envelope.php (1 issue)

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