Passed
Push — master ( 36a506...c71795 )
by Tim
02:51
created

NameIDType   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 164
rs 10
c 0
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 23 5
A getBlacklistedAlgorithms() 0 4 1
A validateContent() 0 3 1
A setSPProvidedID() 0 4 1
A __construct() 0 12 1
A getFormat() 0 3 1
A getEncryptionBackend() 0 5 1
A setFormat() 0 4 1
A getSPProvidedID() 0 3 1
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
use SimpleSAML\SAML2\XML\IDNameQualifiersTrait;
10
use SimpleSAML\XML\XMLStringElementTrait;
11
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
12
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
13
14
/**
15
 * SAML NameIDType abstract data type.
16
 *
17
 * @package simplesamlphp/saml2
18
 */
19
20
abstract class NameIDType extends AbstractSamlElement implements IdentifierInterface, EncryptableElementInterface
21
{
22
    use IDNameQualifiersTrait;
23
    use XMLStringElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\XMLStringElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\saml\NameIDType: $localName, $namespaceURI
Loading history...
24
    use EncryptableElementTrait;
25
26
    /**
27
     * A URI reference representing the classification of string-based identifier information. See Section 8.3 for the
28
     * SAML-defined URI references that MAY be used as the value of the Format attribute and their associated
29
     * descriptions and processing rules. Unless otherwise specified by an element based on this type, if no Format
30
     * value is provided, then the value urn:oasis:names:tc:SAML:1.0:nameid-format:unspecified (see Section 8.3.1) is in
31
     * effect.
32
     *
33
     * When a Format value other than one specified in Section 8.3 is used, the content of an element of this type is to
34
     * be interpreted according to the definition of that format as provided outside of this specification. If not
35
     * otherwise indicated by the definition of the format, issues of anonymity, pseudonymity, and the persistence of
36
     * the identifier with respect to the asserting and relying parties are implementation-specific.
37
     *
38
     * @var string|null
39
     *
40
     * @see saml-core-2.0-os
41
     */
42
    protected ?string $Format = null;
43
44
    /**
45
     * A name identifier established by a service provider or affiliation of providers for the entity, if different from
46
     * the primary name identifier given in the content of the element. This attribute provides a means of integrating
47
     * the use of SAML with existing identifiers already in use by a service provider. For example, an existing
48
     * identifier can be "attached" to the entity using the Name Identifier Management protocol defined in Section 3.6.
49
     *
50
     * @var string|null
51
     *
52
     * @see saml-core-2.0-os
53
     */
54
    protected ?string $SPProvidedID = null;
55
56
57
    /**
58
     * Initialize a saml:NameIDType from scratch
59
     *
60
     * @param string $value
61
     * @param string|null $Format
62
     * @param string|null $SPProvidedID
63
     * @param string|null $NameQualifier
64
     * @param string|null $SPNameQualifier
65
     */
66
    protected function __construct(
67
        string $value,
68
        ?string $NameQualifier = null,
69
        ?string $SPNameQualifier = null,
70
        ?string $Format = null,
71
        ?string $SPProvidedID = null
72
    ) {
73
        $this->setContent($value);
74
        $this->setNameQualifier($NameQualifier);
75
        $this->setSPNameQualifier($SPNameQualifier);
76
        $this->setFormat($Format);
77
        $this->setSPProvidedID($SPProvidedID);
78
    }
79
80
81
    /**
82
     * Collect the value of the Format-property
83
     *
84
     * @return string|null
85
     */
86
    public function getFormat(): ?string
87
    {
88
        return $this->Format;
89
    }
90
91
92
    /**
93
     * Set the value of the Format-property
94
     *
95
     * @param string|null $format
96
     */
97
    private function setFormat(?string $format): void
98
    {
99
        Assert::nullOrNotWhitespaceOnly($format);
100
        $this->Format = $format;
101
    }
102
103
104
    /**
105
     * Collect the value of the SPProvidedID-property
106
     *
107
     * @return string|null
108
     */
109
    public function getSPProvidedID(): ?string
110
    {
111
        return $this->SPProvidedID;
112
    }
113
114
115
    /**
116
     * Set the value of the SPProvidedID-property
117
     *
118
     * @param string|null $spProvidedID
119
     */
120
    public function setSPProvidedID(?string $spProvidedID): void
121
    {
122
        Assert::nullOrNotWhitespaceOnly($spProvidedID);
123
        $this->SPProvidedID = $spProvidedID;
124
    }
125
126
127
    /**
128
     * Validate the content of the element.
129
     *
130
     * @param string $content  The value to go in the XML textContent
131
     * @throws \Exception on failure
132
     * @return void
133
     */
134
    protected function validateContent(string $content): void
135
    {
136
        Assert::notWhitespaceOnly($content);
137
    }
138
139
140
    /**
141
     * Convert this NameIDType to XML.
142
     *
143
     * @param \DOMElement $parent The element we are converting to XML.
144
     * @return \DOMElement The XML element after adding the data corresponding to this NameIDType.
145
     */
146
    public function toXML(DOMElement $parent = null): DOMElement
147
    {
148
        /** @psalm-var \DOMDocument $element->ownerDocument */
149
        $element = $this->instantiateParentElement($parent);
150
151
        if ($this->NameQualifier !== null) {
152
            $element->setAttribute('NameQualifier', $this->NameQualifier);
153
        }
154
155
        if ($this->SPNameQualifier !== null) {
156
            $element->setAttribute('SPNameQualifier', $this->SPNameQualifier);
157
        }
158
159
        if ($this->Format !== null) {
160
            $element->setAttribute('Format', $this->Format);
161
        }
162
163
        if ($this->SPProvidedID !== null) {
164
            $element->setAttribute('SPProvidedID', $this->SPProvidedID);
165
        }
166
167
        $element->textContent = $this->content;
168
        return $element;
169
    }
170
171
172
    public function getBlacklistedAlgorithms(): ?array
173
    {
174
        // return an array with the algorithms you don't want to allow to be used
175
        return [];
176
    }
177
178
179
    public function getEncryptionBackend(): ?EncryptionBackend
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\EncryptionBackend was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
180
    {
181
        // return the encryption backend you want to use,
182
        // or null if you are fine with the default
183
        return null;
184
    }
185
}
186