Passed
Push — master ( 8c2723...6ca2a7 )
by Tim
02:37
created

Audience::fromXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 1
b 1
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
     * Convert XML into an Audience
29
     *
30
     * @param \DOMElement $xml The XML element we should load
31
     * @return self
32
     *
33
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
34
     *   If the qualified name of the supplied element is wrong
35
     */
36
    public static function fromXML(DOMElement $xml): object
37
    {
38
        Assert::same($xml->localName, 'Audience', InvalidDOMElementException::class);
39
        Assert::same($xml->namespaceURI, Audience::NS, InvalidDOMElementException::class);
40
41
        return new self($xml->textContent);
42
    }
43
44
45
    /**
46
     * Convert this Audience to XML.
47
     *
48
     * @param \DOMElement $parent The element we are converting to XML.
49
     * @return \DOMElement The XML element after adding the data corresponding to this Condition.
50
     */
51
    public function toXML(DOMElement $parent = null): DOMElement
52
    {
53
        $element = $this->instantiateParentElement($parent);
54
        $element->textContent = $this->value;
0 ignored issues
show
Bug Best Practice introduced by
The property value does not exist on SimpleSAML\SAML2\XML\saml\Audience. Did you maybe forget to declare it?
Loading history...
55
56
        return $element;
57
    }
58
}
59
60