RelatesTo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 22
dl 0
loc 82
c 0
b 0
f 0
rs 10

4 Methods

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