Issues (16)

src/SOAP11/XML/Header.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP11\XML;
6
7
use DOMElement;
8
use SimpleSAML\SOAP11\Assert\Assert;
9
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
10
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum;
13
14
/**
15
 * Class representing a SOAP-ENV:Header element.
16
 *
17
 * @package simplesaml/xml-soap
18
 */
19
final class Header extends AbstractSoapElement implements SchemaValidatableElementInterface
20
{
21
    use ExtendableAttributesTrait;
22
    use ExtendableElementTrait;
23
    use SchemaValidatableElementTrait;
24
25
    /** The namespace-attribute for the xs:any element */
26
    public const XS_ANY_ELT_NAMESPACE = NamespaceEnum::Other;
27
28
    /** The namespace-attribute for the xs:anyAttribute element */
29
    public const XS_ANY_ATTR_NAMESPACE = NamespaceEnum::Other;
30
31
32
    /**
33
     * Initialize a SOAP-ENV:Header
34
     *
35
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
36
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
The type SimpleSAML\SOAP11\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...
37
     */
38
    public function __construct(array $children = [], array $namespacedAttributes = [])
39
    {
40
        $this->setElements($children);
41
        $this->setAttributesNS($namespacedAttributes);
42
    }
43
44
45
    /**
46
     * Test if an object, at the state it's in, would produce an empty XML-element
47
     *
48
     * @return bool
49
     */
50
    public function isEmptyElement(): bool
51
    {
52
        return empty($this->elements) && empty($this->namespacedAttributes);
53
    }
54
55
56
    /*
57
     * Convert XML into an Header element
58
     *
59
     * @param \DOMElement $xml The XML element we should load
60
     * @return static
61
     *
62
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
63
     *   If the qualified name of the supplied element is wrong
64
     */
65
    public static function fromXML(DOMElement $xml): static
66
    {
67
        Assert::same($xml->localName, 'Header', InvalidDOMElementException::class);
68
        Assert::same($xml->namespaceURI, Header::NS, InvalidDOMElementException::class);
69
70
        return new static(
71
            self::getChildElementsFromXML($xml),
72
            self::getAttributesNSFromXML($xml),
73
        );
74
    }
75
76
77
    /**
78
     * Convert this Header to XML.
79
     *
80
     * @param \DOMElement|null $parent The element we should add this header to.
81
     * @return \DOMElement This Header-element.
82
     */
83
    public function toXML(?DOMElement $parent = null): DOMElement
84
    {
85
        $e = $this->instantiateParentElement($parent);
86
87
        foreach ($this->getAttributesNS() as $attr) {
88
            $attr->toXML($e);
89
        }
90
91
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
92
        foreach ($this->getElements() as $child) {
93
            $child->toXML($e);
94
        }
95
96
        return $e;
97
    }
98
}
99