AbstractEvidenceType::isEmptyElement()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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