AdditionalMetadataLocation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 7 1
A fromXML() 0 8 1
A getNamespace() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML2\Assert\Assert as SAMLAssert;
10
use SimpleSAML\SAML2\XML\URIElementTrait;
11
use SimpleSAML\XML\Exception\InvalidDOMElementException;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
15
use function trim;
16
17
/**
18
 * Class representing SAML 2 metadata AdditionalMetadataLocation element.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class AdditionalMetadataLocation extends AbstractMdElement implements SchemaValidatableElementInterface
23
{
24
    use SchemaValidatableElementTrait;
25
    use URIElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\SAML2\XML\URIElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\md\AdditionalMetadataLocation: $localName, $namespaceURI
Loading history...
26
27
28
    /**
29
     * Create a new instance of AdditionalMetadataLocation
30
     *
31
     * @param string $namespace
32
     * @param string $location
33
     */
34
    public function __construct(
35
        protected string $namespace,
36
        string $location,
37
    ) {
38
        SAMLAssert::validURI($namespace);
39
        $this->setContent($location);
40
    }
41
42
43
    /**
44
     * Collect the value of the namespace-property
45
     *
46
     * @return string
47
     */
48
    public function getNamespace(): string
49
    {
50
        return $this->namespace;
51
    }
52
53
54
    /**
55
     * Initialize an AdditionalMetadataLocation element.
56
     *
57
     * @param \DOMElement $xml The XML element we should load.
58
     * @return static
59
     *
60
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
61
     *   if the qualified name of the supplied element is wrong
62
     * @throws \SimpleSAML\XML\Exception\MissingAttributeException
63
     *   if the supplied element is missing any of the mandatory attributes
64
     */
65
    public static function fromXML(DOMElement $xml): static
66
    {
67
        Assert::same($xml->localName, 'AdditionalMetadataLocation', InvalidDOMElementException::class);
68
        Assert::same($xml->namespaceURI, AdditionalMetadataLocation::NS, InvalidDOMElementException::class);
69
70
        $namespace = self::getAttribute($xml, 'namespace');
71
72
        return new static($namespace, trim($xml->textContent));
73
    }
74
75
76
    /**
77
     * Convert this AdditionalMetadataLocation to XML.
78
     *
79
     * @param \DOMElement|null $parent The element we should append to.
80
     * @return \DOMElement This AdditionalMetadataLocation-element.
81
     */
82
    public function toXML(?DOMElement $parent = null): DOMElement
83
    {
84
        $e = $this->instantiateParentElement($parent);
85
        $e->textContent = $this->getContent();
86
        $e->setAttribute('namespace', $this->getNamespace());
87
88
        return $e;
89
    }
90
}
91