Passed
Push — master ( 271d39...55cc91 )
by Tim
02:25
created

Audience::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\saml;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
11
/**
12
 * Class representing a saml:Audience element.
13
 *
14
 * @package simplesaml/saml2
15
 */
16
final class Audience extends AbstractConditionType
17
{
18
    /**
19
     * @param string $content
20
     */
21
    public function __construct(string $content)
22
    {
23
        $this->setContent($content);
24
    }
25
26
27
    /**
28
     * Validate the content of the element.
29
     *
30
     * @param string $content  The value to go in the XML textContent
31
     * @throws \Exception on failure
32
     * @return void
33
     */
34
    protected function validateContent(string $content): void
35
    {
36
        Assert::validURI($content); // Covers the empty string
37
    }
38
39
40
    /**
41
     * Convert XML into an Audience
42
     *
43
     * @param \DOMElement $xml The XML element we should load
44
     * @return self
45
     *
46
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
47
     *   If the qualified name of the supplied element is wrong
48
     */
49
    public static function fromXML(DOMElement $xml): object
50
    {
51
        Assert::same($xml->localName, 'Audience', InvalidDOMElementException::class);
52
        Assert::same($xml->namespaceURI, Audience::NS, InvalidDOMElementException::class);
53
54
        return new self($xml->textContent);
55
    }
56
57
58
    /**
59
     * Convert this Audience to XML.
60
     *
61
     * @param \DOMElement $parent The element we are converting to XML.
62
     * @return \DOMElement The XML element after adding the data corresponding to this Condition.
63
     */
64
    public function toXML(DOMElement $parent = null): DOMElement
65
    {
66
        $element = $this->instantiateParentElement($parent);
67
        $element->textContent = $this->content;
68
69
        return $element;
70
    }
71
}
72
73