AbstractAudienceRestrictionConditionType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 63
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAudience() 0 3 1
A toXML() 0 9 2
A __construct() 0 4 1
A fromXML() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
10
use SimpleSAML\XMLSchema\Exception\MissingElementException;
11
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12
13
/**
14
 * @package simplesamlphp\saml11
15
 */
16
abstract class AbstractAudienceRestrictionConditionType extends AbstractConditionType
17
{
18
    /**
19
     * AudienceRestrictionConditionType constructor.
20
     *
21
     * @param \SimpleSAML\SAML11\XML\saml\Audience[] $audience
22
     */
23
    final public function __construct(
24
        protected array $audience,
25
    ) {
26
        Assert::allIsInstanceOf($audience, Audience::class, SchemaViolationException::class);
27
    }
28
29
30
    /**
31
     * Get the value of the audience-attribute.
32
     *
33
     * @return \SimpleSAML\SAML11\XML\saml\Audience[]
34
     */
35
    public function getAudience(): array
36
    {
37
        return $this->audience;
38
    }
39
40
41
    /**
42
     * Convert XML into a AudienceRestrictionCondition
43
     *
44
     * @param \DOMElement $xml The XML element we should load
45
     * @return static
46
     *
47
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
48
     *   if the qualified name of the supplied element is wrong
49
     */
50
    public static function fromXML(DOMElement $xml): static
51
    {
52
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
53
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
54
55
        $audience = Audience::getChildrenOfClass($xml);
56
        Assert::minCount($audience, 1, MissingElementException::class);
57
58
        return new static(
59
            $audience,
60
        );
61
    }
62
63
64
    /**
65
     * Convert this AudienceRestrictionCondition to XML.
66
     *
67
     * @param \DOMElement $parent The element we are converting to XML.
68
     * @return \DOMElement The XML element after adding the data corresponding to this AudienceRestrictionCondition.
69
     */
70
    public function toXML(?DOMElement $parent = null): DOMElement
71
    {
72
        $e = $this->instantiateParentElement($parent);
73
74
        foreach ($this->getAudience() as $a) {
75
            $a->toXML($e);
76
        }
77
78
        return $e;
79
    }
80
}
81