Passed
Pull Request — master (#374)
by Tim
02:32
created

AdditionalMetadataLocation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
12
13
/**
14
 * Class representing SAML 2 metadata AdditionalMetadataLocation element.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
final class AdditionalMetadataLocation extends AbstractMdElement implements SchemaValidatableElementInterface
19
{
20
    use SchemaValidatableElementTrait;
21
22
23
    /**
24
     * Create a new instance of AdditionalMetadataLocation
25
     *
26
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $namespace
27
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $location
28
     */
29
    public function __construct(
30
        protected SAMLAnyURIValue $namespace,
31
        protected SAMLAnyURIValue $location,
32
    ) {
33
    }
34
35
36
    /**
37
     * Collect the value of the namespace-property
38
     *
39
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue
40
     */
41
    public function getNamespace(): SAMLAnyURIValue
42
    {
43
        return $this->namespace;
44
    }
45
46
47
    /**
48
     * Collect the value of the location-property
49
     *
50
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue
51
     */
52
    public function getLocation(): SAMLAnyURIValue
53
    {
54
        return $this->location;
55
    }
56
57
58
    /**
59
     * Initialize an AdditionalMetadataLocation element.
60
     *
61
     * @param \DOMElement $xml The XML element we should load.
62
     * @return static
63
     *
64
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
65
     *   if the qualified name of the supplied element is wrong
66
     * @throws \SimpleSAML\XML\Exception\MissingAttributeException
67
     *   if the supplied element is missing any of the mandatory attributes
68
     */
69
    public static function fromXML(DOMElement $xml): static
70
    {
71
        Assert::same($xml->localName, 'AdditionalMetadataLocation', InvalidDOMElementException::class);
72
        Assert::same($xml->namespaceURI, AdditionalMetadataLocation::NS, InvalidDOMElementException::class);
73
74
        return new static(
75
            self::getAttribute($xml, 'namespace', SAMLAnyURIValue::class),
76
            SAMLAnyURIValue::fromString($xml->textContent),
77
        );
78
    }
79
80
81
    /**
82
     * Convert this AdditionalMetadataLocation to XML.
83
     *
84
     * @param \DOMElement|null $parent The element we should append to.
85
     * @return \DOMElement This AdditionalMetadataLocation-element.
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = $this->instantiateParentElement($parent);
90
        $e->textContent = $this->getLocation()->getValue();
91
        $e->setAttribute('namespace', $this->getNamespace()->getValue());
92
93
        return $e;
94
    }
95
}
96