Passed
Push — master ( 92085d...93354f )
by Tim
02:29
created

AdditionalMetadataLocation::validateContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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