AbstractEvidenceType::getAssertion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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\SAML11\Constants as C;
10
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException};
11
12
/**
13
 * SAML EvidenceType abstract data type.
14
 *
15
 * @package simplesamlphp/saml11
16
 */
17
abstract class AbstractEvidenceType extends AbstractSamlElement
18
{
19
    /**
20
     * Initialize a saml:EvidenceType from scratch
21
     *
22
     * @param array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference> $assertionIDReference
23
     * @param array<\SimpleSAML\SAML11\XML\saml\Assertion> $assertion
24
     */
25
    final public function __construct(
26
        protected array $assertionIDReference = [],
27
        protected array $assertion = [],
28
    ) {
29
        Assert::maxCount($assertionIDReference, C::UNBOUNDED_LIMIT);
30
        Assert::maxCount($assertion, C::UNBOUNDED_LIMIT);
31
        Assert::allIsInstanceOf($assertionIDReference, AssertionIDReference::class, SchemaViolationException::class);
32
        Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class);
33
    }
34
35
36
    /**
37
     * Collect the value of the assertionIDReference-property
38
     *
39
     * @return array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference>
40
     */
41
    public function getAssertionIDReference(): array
42
    {
43
        return $this->assertionIDReference;
44
    }
45
46
47
    /**
48
     * Collect the value of the assertion-property
49
     *
50
     * @return array<\SimpleSAML\SAML11\XML\saml\Assertion>
51
     */
52
    public function getAssertion(): array
53
    {
54
        return $this->assertion;
55
    }
56
57
58
    /**
59
     * Test if an object, at the state it's in, would produce an empty XML-element
60
     *
61
     * @return bool
62
     */
63
    public function isEmptyElement(): bool
64
    {
65
        return empty($this->assertionIDReference)
66
            && empty($this->assertion);
67
    }
68
69
70
    /**
71
     * Convert XML into an EvidenceType
72
     *
73
     * @param \DOMElement $xml The XML element we should load
74
     * @return static
75
     *
76
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
77
     *   if the qualified name of the supplied element is wrong
78
     */
79
    public static function fromXML(DOMElement $xml): static
80
    {
81
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
82
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
83
84
        return new static(
85
            AssertionIDReference::getChildrenOfClass($xml),
86
            Assertion::getChildrenOfClass($xml),
87
        );
88
    }
89
90
91
    /**
92
     * Convert this EvidenceType to XML.
93
     *
94
     * @param \DOMElement $parent The element we are converting to XML.
95
     * @return \DOMElement The XML element after adding the data corresponding to this EvidenceType.
96
     */
97
    public function toXML(?DOMElement $parent = null): DOMElement
98
    {
99
        $e = $this->instantiateParentElement($parent);
100
101
        foreach ($this->getAssertionIDReference() as $assertionIDRef) {
102
            $assertionIDRef->toXML($e);
103
        }
104
105
        foreach ($this->getAssertion() as $assertion) {
106
            $assertion->toXML($e);
107
        }
108
109
        return $e;
110
    }
111
}
112