Passed
Push — master ( 0aff4f...e61fad )
by Tim
02:24
created

Audience   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 9
c 1
b 1
f 0
dl 0
loc 44
rs 10
wmc 3

3 Methods

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