AbstractSubjectConfirmationType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 98
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getSubjectConfirmationData() 0 3 1
A getKeyInfo() 0 3 1
A toXML() 0 12 2
A fromXML() 0 15 1
A getConfirmationMethod() 0 3 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
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
13
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo;
14
15
/**
16
 * SAML SubjectConfirmationType abstract data type.
17
 *
18
 * @package simplesamlphp/saml11
19
 */
20
abstract class AbstractSubjectConfirmationType extends AbstractSamlElement
21
{
22
    /**
23
     * Initialize a saml:SubjectConfirmationType from scratch
24
     *
25
     * @param array<\SimpleSAML\SAML11\XML\saml\ConfirmationMethod> $confirmationMethod
26
     * @param \SimpleSAML\SAML11\XML\saml\SubjectConfirmationData|null $subjectConfirmationData
27
     * @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo
28
     */
29
    final public function __construct(
30
        protected array $confirmationMethod,
31
        protected ?SubjectConfirmationData $subjectConfirmationData = null,
32
        protected ?KeyInfo $keyInfo = null,
33
    ) {
34
        Assert::minCount($confirmationMethod, 1, MissingElementException::class);
35
        Assert::allIsInstanceOf($confirmationMethod, ConfirmationMethod::class, SchemaViolationException::class);
36
    }
37
38
39
    /**
40
     * Collect the value of the confirmationMethod-property
41
     *
42
     * @return array<\SimpleSAML\SAML11\XML\saml\ConfirmationMethod>
43
     */
44
    public function getConfirmationMethod(): array
45
    {
46
        return $this->confirmationMethod;
47
    }
48
49
50
    /**
51
     * Collect the value of the subjectConfirmationData-property
52
     *
53
     * @return \SimpleSAML\SAML11\XML\saml\SubjectConfirmationData|null
54
     */
55
    public function getSubjectConfirmationData(): ?SubjectConfirmationData
56
    {
57
        return $this->subjectConfirmationData;
58
    }
59
60
61
    /**
62
     * Collect the value of the keyInfo-property
63
     *
64
     * @return \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null
65
     */
66
    public function getKeyInfo(): ?KeyInfo
67
    {
68
        return $this->keyInfo;
69
    }
70
71
72
    /**
73
     * Convert XML into an SubjectConfirmationType
74
     *
75
     * @param \DOMElement $xml The XML element we should load
76
     * @return static
77
     *
78
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
79
     *   if the qualified name of the supplied element is wrong
80
     */
81
    public static function fromXML(DOMElement $xml): static
82
    {
83
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
84
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
85
86
        $subjectConfirmationData = SubjectConfirmationData::getChildrenOfClass($xml);
87
        Assert::maxCount($subjectConfirmationData, 1, TooManyElementsException::class);
88
89
        $keyInfo = KeyInfo::getChildrenOfClass($xml);
90
        Assert::maxCount($keyInfo, 1, TooManyElementsException::class);
91
92
        return new static(
93
            ConfirmationMethod::getChildrenOfClass($xml),
94
            array_pop($subjectConfirmationData),
95
            array_pop($keyInfo),
96
        );
97
    }
98
99
100
    /**
101
     * Convert this SubjectConfirmationType to XML.
102
     *
103
     * @param \DOMElement $parent The element we are converting to XML.
104
     * @return \DOMElement The XML element after adding the data corresponding to this SubjectConfirmationType.
105
     */
106
    public function toXML(?DOMElement $parent = null): DOMElement
107
    {
108
        $e = $this->instantiateParentElement($parent);
109
110
        foreach ($this->getConfirmationMethod() as $confirmationMethod) {
111
            $confirmationMethod->toXML($e);
112
        }
113
114
        $this->getSubjectConfirmationData()?->toXML($e);
115
        $this->getKeyInfo()?->toXML($e);
116
117
        return $e;
118
    }
119
}
120