Passed
Pull Request — master (#307)
by Tim
03:20
created

AbstractBaseIDType::toXML()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
10
/**
11
 * SAML BaseID data type.
12
 *
13
 * @package simplesamlphp/saml2
14
 */
15
abstract class AbstractBaseIDType extends AbstractSamlElement implements BaseIdentifierInterface
16
{
17
    /**
18
     * The security or administrative domain that qualifies the identifier.
19
     * This attribute provides a means to federate identifiers from disparate user stores without collision.
20
     *
21
     * @see saml-core-2.0-os
22
     *
23
     * @var string|null
24
     */
25
    protected ?string $NameQualifier = null;
26
27
    /**
28
     * Further qualifies an identifier with the name of a service provider or affiliation of providers.
29
     * This attribute provides an additional means to federate identifiers on the basis of the relying party or parties.
30
     *
31
     * @see saml-core-2.0-os
32
     *
33
     * @var string|null
34
     */
35
    protected ?string $SPNameQualifier = null;
36
37
38
    /**
39
     * Initialize a saml:BaseIDAbstractType from scratch
40
     *
41
     * @param string|null $NameQualifier
42
     * @param string|null $SPNameQualifier
43
     */
44
    protected function __construct(
45
        ?string $NameQualifier = null,
46
        ?string $SPNameQualifier = null
47
    ) {
48
        $this->setNameQualifier($NameQualifier);
49
        $this->setSPNameQualifier($SPNameQualifier);
50
    }
51
52
53
    /**
54
     * Collect the value of the NameQualifier-property
55
     *
56
     * @return string|null
57
     */
58
    public function getNameQualifier(): ?string
59
    {
60
        return $this->NameQualifier;
61
    }
62
63
64
    /**
65
     * Set the value of the NameQualifier-property
66
     *
67
     * @param string|null $nameQualifier
68
     */
69
    private function setNameQualifier(?string $nameQualifier): void
70
    {
71
        Assert::nullOrNotWhitespaceOnly($nameQualifier);
72
        $this->NameQualifier = $nameQualifier;
73
    }
74
75
    /**
76
     * Collect the value of the SPNameQualifier-property
77
     *
78
     * @return string|null
79
     */
80
    public function getSPNameQualifier(): ?string
81
    {
82
        return $this->SPNameQualifier;
83
    }
84
85
86
    /**
87
     * Set the value of the SPNameQualifier-property
88
     *
89
     * @param string|null $spNameQualifier
90
     */
91
    private function setSPNameQualifier(?string $spNameQualifier): void
92
    {
93
        Assert::nullOrNotWhitespaceOnly($spNameQualifier);
94
        $this->SPNameQualifier = $spNameQualifier;
95
    }
96
97
98
    /**
99
     * Convert this BaseID to XML.
100
     *
101
     * @param \DOMElement $parent The element we are converting to XML.
102
     * @return \DOMElement The XML element after adding the data corresponding to this BaseID.
103
     */
104
    public function toXML(DOMElement $parent = null): DOMElement
105
    {
106
        $e = $this->instantiateParentElement($parent);
107
108
        if ($this->NameQualifier !== null) {
109
            $e->setAttribute('NameQualifier', $this->NameQualifier);
110
        }
111
112
        if ($this->SPNameQualifier !== null) {
113
            $e->setAttribute('SPNameQualifier', $this->SPNameQualifier);
114
        }
115
116
        return $e;
117
    }
118
}
119