Passed
Push — master ( 49bdee...6e4a83 )
by Tim
03:31
created

RelatesTo::isEmptyElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200508;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\SchemaViolationException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\URIElementTrait;
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class representing a wsa:RelatesTo element.
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
final class RelatesTo extends AbstractWsaElement
21
{
22
    use ExtendableAttributesTrait;
23
    use URIElementTrait;
24
25
    /** The namespace-attribute for the xs:anyAttribute element */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
27
28
29
    /**
30
     * Initialize a wsa:RelatesTo
31
     *
32
     * @param string $content
33
     * @param string|null $RelationshipType
34
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsa_200508\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...
35
     */
36
    public function __construct(
37
        string $content,
38
        protected ?string $RelationshipType = 'http://www.w3.org/2005/08/addressing/reply',
39
        array $namespacedAttributes = [],
40
    ) {
41
        Assert::nullOrValidURI($RelationshipType, SchemaViolationException::class);
42
43
        $this->setContent($content);
44
        $this->setAttributesNS($namespacedAttributes);
45
    }
46
47
48
    /**
49
     * Collect the value of the RelationshipType property.
50
     *
51
     * @return string|null
52
     */
53
    public function getRelationshipType(): ?string
54
    {
55
        return $this->RelationshipType;
56
    }
57
58
59
    /*
60
     * Convert XML into an RelatesTo element
61
     *
62
     * @param \DOMElement $xml The XML element we should load
63
     * @return static
64
     *
65
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
66
     *   If the qualified name of the supplied element is wrong
67
     */
68
    public static function fromXML(DOMElement $xml): static
69
    {
70
        Assert::same($xml->localName, 'RelatesTo', InvalidDOMElementException::class);
71
        Assert::same($xml->namespaceURI, RelatesTo::NS, InvalidDOMElementException::class);
72
73
        return new static(
74
            $xml->textContent,
75
            self::getOptionalAttribute($xml, 'RelationshipType', null),
76
            self::getAttributesNSFromXML($xml),
77
        );
78
    }
79
80
81
    /**
82
     * Convert this RelatesTo to XML.
83
     *
84
     * @param \DOMElement|null $parent The element we should add this RelatesTo to.
85
     * @return \DOMElement This Header-element.
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = $this->instantiateParentElement($parent);
90
        $e->textContent = $this->getContent();
91
92
        if ($this->getRelationshipType() !== null) {
93
            $e->setAttribute('RelationshipType', $this->getRelationshipType());
94
        }
95
96
        foreach ($this->getAttributesNS() as $attr) {
97
            $attr->toXML($e);
98
        }
99
100
        return $e;
101
    }
102
}
103