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