Passed
Pull Request — master (#307)
by Tim
02:30
created

NameIDType::getEncryptionBackend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 5
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
use SimpleSAML\SAML2\Compat\ContainerSingleton;
10
use SimpleSAML\XML\StringElementTrait;
11
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
12
use SimpleSAML\XMLSecurity\Constants as C;
13
14
/**
15
 * SAML NameIDType abstract data type.
16
 *
17
 * @package simplesamlphp/saml2
18
 */
19
20
abstract class NameIDType extends AbstractBaseIDType
21
{
22
    use StringElementTrait;
23
    use EncryptableElementTrait;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\EncryptableElementTrait 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...
24
25
    /**
26
     * A URI reference representing the classification of string-based identifier information. See Section 8.3 for the
27
     * SAML-defined URI references that MAY be used as the value of the Format attribute and their associated
28
     * descriptions and processing rules. Unless otherwise specified by an element based on this type, if no Format
29
     * value is provided, then the value urn:oasis:names:tc:SAML:1.0:nameid-format:unspecified (see Section 8.3.1) is in
30
     * effect.
31
     *
32
     * When a Format value other than one specified in Section 8.3 is used, the content of an element of this type is to
33
     * be interpreted according to the definition of that format as provided outside of this specification. If not
34
     * otherwise indicated by the definition of the format, issues of anonymity, pseudonymity, and the persistence of
35
     * the identifier with respect to the asserting and relying parties are implementation-specific.
36
     *
37
     * @var string|null
38
     *
39
     * @see saml-core-2.0-os
40
     */
41
    protected ?string $Format = null;
42
43
    /**
44
     * A name identifier established by a service provider or affiliation of providers for the entity, if different from
45
     * the primary name identifier given in the content of the element. This attribute provides a means of integrating
46
     * the use of SAML with existing identifiers already in use by a service provider. For example, an existing
47
     * identifier can be "attached" to the entity using the Name Identifier Management protocol defined in Section 3.6.
48
     *
49
     * @var string|null
50
     *
51
     * @see saml-core-2.0-os
52
     */
53
    protected ?string $SPProvidedID = null;
54
55
56
    /**
57
     * Initialize a saml:NameIDType from scratch
58
     *
59
     * @param string $value
60
     * @param string|null $Format
61
     * @param string|null $SPProvidedID
62
     * @param string|null $NameQualifier
63
     * @param string|null $SPNameQualifier
64
     */
65
    protected function __construct(
66
        string $value,
67
        ?string $NameQualifier = null,
68
        ?string $SPNameQualifier = null,
69
        ?string $Format = null,
70
        ?string $SPProvidedID = null
71
    ) {
72
        parent::__construct($NameQualifier, $SPNameQualifier);
73
        $this->dataType = C::XMLENC_ELEMENT;
0 ignored issues
show
Bug Best Practice introduced by
The property dataType does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
74
75
        $this->setContent($value);
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::nullOrValidURI($format); // Covers the empty string
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
    private 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
        $e = parent::toXML($parent);
149
150
        if ($this->Format !== null) {
151
            $e->setAttribute('Format', $this->Format);
152
        }
153
154
        if ($this->SPProvidedID !== null) {
155
            $e->setAttribute('SPProvidedID', $this->SPProvidedID);
156
        }
157
158
        $e->textContent = $this->content;
159
        return $e;
160
    }
161
}
162