Issues (16)

src/SOAP12/XML/Body.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\SOAP12\Exception\ProtocolViolationException;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XML\ExtendableElementTrait;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
use SimpleSAML\XMLSchema\XML\Constants\NS;
16
17
use function array_pop;
18
19
/**
20
 * Class representing a env:Body element.
21
 *
22
 * @package simplesaml/xml-soap
23
 */
24
final class Body extends AbstractSoapElement implements SchemaValidatableElementInterface
25
{
26
    use ExtendableAttributesTrait;
27
    use ExtendableElementTrait;
28
    use SchemaValidatableElementTrait;
29
30
31
    /** The namespace-attribute for the xs:any element */
32
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
33
34
    /** The namespace-attribute for the xs:anyAttribute element */
35
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
36
37
38
    /**
39
     * Initialize a soap:Body
40
     *
41
     * @param \SimpleSAML\SOAP12\XML\Fault|null $fault
42
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
43
     * @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...
44
     */
45
    public function __construct(
46
        protected ?Fault $fault = null,
47
        array $children = [],
48
        array $namespacedAttributes = [],
49
    ) {
50
        if ($fault !== null) {
51
            /**
52
             * 5.4: When generating a fault, SOAP senders MUST NOT include additional element
53
             *      information items in the SOAP Body .
54
             */
55
            Assert::isEmpty(
56
                $children,
57
                "When generating a fault, SOAP senders MUST NOT include additional elements in the SOAP Body.",
58
                ProtocolViolationException::class,
59
            );
60
        }
61
        Assert::allNotInstanceOf($children, Fault::class, ProtocolViolationException::class);
62
63
        $this->setElements($children);
64
        $this->setAttributesNS($namespacedAttributes);
65
    }
66
67
68
    /**
69
     * @return \SimpleSAML\SOAP12\XML\Fault|null
70
     */
71
    public function getFault(): ?Fault
72
    {
73
        return $this->fault;
74
    }
75
76
77
    /**
78
     * Test if an object, at the state it's in, would produce an empty XML-element
79
     *
80
     * @return bool
81
     */
82
    public function isEmptyElement(): bool
83
    {
84
        return empty($this->fault) && empty($this->elements) && empty($this->namespacedAttributes);
85
    }
86
87
88
    /*
89
     * Convert XML into an Body element
90
     *
91
     * @param \DOMElement $xml The XML element we should load
92
     * @return static
93
     *
94
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
95
     *   If the qualified name of the supplied element is wrong
96
     */
97
    public static function fromXML(DOMElement $xml): static
98
    {
99
        Assert::same($xml->localName, 'Body', InvalidDOMElementException::class);
100
        Assert::same($xml->namespaceURI, Body::NS, InvalidDOMElementException::class);
101
102
        /**
103
         * 5.4: To be recognized as carrying SOAP error information, a SOAP message MUST contain a single SOAP Fault
104
         *      element information item as the only child element information item of the SOAP Body .
105
         */
106
        $fault = Fault::getChildrenOfClass($xml);
107
        Assert::maxCount($fault, 1, ProtocolViolationException::class);
108
109
        return new static(
110
            array_pop($fault),
111
            self::getChildElementsFromXML($xml),
112
            self::getAttributesNSFromXML($xml),
113
        );
114
    }
115
116
117
    /**
118
     * Convert this Body to XML.
119
     *
120
     * @param \DOMElement|null $parent The element we should add this Body to.
121
     * @return \DOMElement This Body-element.
122
     */
123
    public function toXML(?DOMElement $parent = null): DOMElement
124
    {
125
        $e = $this->instantiateParentElement($parent);
126
127
        foreach ($this->getAttributesNS() as $attr) {
128
            $attr->toXML($e);
129
        }
130
131
        $this->getFault()?->toXML($e);
132
133
        foreach ($this->getElements() as $child) {
134
            $child->toXML($e);
135
        }
136
137
        return $e;
138
    }
139
}
140