Passed
Push — master ( fb0d53...7c0351 )
by Jaime Pérez
03:11
created

NameIDType::fromArray()   B

Complexity

Conditions 10
Paths 17

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 13
nc 17
nop 1
dl 0
loc 21
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * SAML NameIDType abstract data type.
4
 *
5
 * @author Jaime Pérez Crespo, UNINETT AS <[email protected]>
6
 * @package simplesamlphp/saml2
7
 */
8
9
namespace SAML2\XML\saml;
10
11
abstract class NameIDType extends BaseIDType
12
{
13
    /**
14
     * A URI reference representing the classification of string-based identifier information. See Section 8.3 for the
15
     * SAML-defined URI references that MAY be used as the value of the Format attribute and their associated
16
     * descriptions and processing rules. Unless otherwise specified by an element based on this type, if no Format
17
     * value is provided, then the value urn:oasis:names:tc:SAML:1.0:nameid-format:unspecified (see Section 8.3.1) is in
18
     * effect.
19
     *
20
     * When a Format value other than one specified in Section 8.3 is used, the content of an element of this type is to
21
     * be interpreted according to the definition of that format as provided outside of this specification. If not
22
     * otherwise indicated by the definition of the format, issues of anonymity, pseudonymity, and the persistence of
23
     * the identifier with respect to the asserting and relying parties are implementation-specific.
24
     *
25
     * @var string|null
26
     *
27
     * @see saml-core-2.0-os
28
     */
29
    public $Format = null;
30
31
    /**
32
     * A name identifier established by a service provider or affiliation of providers for the entity, if different from
33
     * the primary name identifier given in the content of the element. This attribute provides a means of integrating
34
     * the use of SAML with existing identifiers already in use by a service provider. For example, an existing
35
     * identifier can be "attached" to the entity using the Name Identifier Management protocol defined in Section 3.6.
36
     *
37
     * @var string|null
38
     *
39
     * @see saml-core-2.0-os
40
     */
41
    public $SPProvidedID = null;
42
43
    /**
44
     * The NameIDType complex type is used when an element serves to represent an entity by a string-valued name.
45
     *
46
     * @var string|null
47
     */
48
    public $value = null;
49
50
51
    /**
52
     * Initialize a saml:NameIDType, either from scratch or from an existing \DOMElement.
53
     *
54
     * @param \DOMElement|null $xml The XML element we should load, if any.
55
     */
56
    public function __construct(\DOMElement $xml = null)
57
    {
58
        parent::__construct($xml);
59
60
        if ($xml === null) {
61
            return;
62
        }
63
64
        if ($xml->hasAttribute('Format')) {
65
            $this->setFormat($xml->getAttribute('Format'));
66
        }
67
68
        if ($xml->hasAttribute('SPProvidedID')) {
69
            $this->setSPProvidedID($xml->getAttribute('SPProvidedID'));
70
        }
71
72
        $this->setValue(trim($xml->textContent));
73
    }
74
75
76
    /**
77
     * Collect the value of the Format-property
78
     * @return string|null
79
     */
80
    public function getFormat()
81
    {
82
        return $this->Format;
83
    }
84
85
86
    /**
87
     * Set the value of the Format-property
88
     * @param string|null $format
89
     * @return void
90
     */
91
    public function setFormat($format = null)
92
    {
93
        assert(is_string($format) || is_null($format));
94
        $this->Format = $format;
95
    }
96
97
98
    /**
99
     * Collect the value of the value-property
100
     * @return string|null
101
     */
102
    public function getValue()
103
    {
104
        return $this->value;
105
    }
106
107
108
    /**
109
     * Set the value of the value-property
110
     * @param string|null $value
111
     * @return void
112
     */
113
    public function setValue($value)
114
    {
115
        assert(is_string($value) || is_null($value));
116
        $this->value = $value;
117
    }
118
119
120
    /**
121
     * Collect the value of the SPProvidedID-property
122
     * @return string|null
123
     */
124
    public function getSPProvidedID()
125
    {
126
        return $this->SPProvidedID;
127
    }
128
129
130
    /**
131
     * Set the value of the SPProvidedID-property
132
     * @param string|null $spProvidedID
133
     * @return void
134
     */
135
    public function setSPProvidedID($spProvidedID)
136
    {
137
        assert(is_string($spProvidedID) || is_null($spProvidedID));
138
        $this->SPProvidedID = $spProvidedID;
139
    }
140
141
142
    /**
143
     * Convert this NameIDType to XML.
144
     *
145
     * @param \DOMElement $parent The element we are converting to XML.
146
     * @return \DOMElement The XML element after adding the data corresponding to this NameIDType.
147
     */
148
    public function toXML(\DOMElement $parent = null)
149
    {
150
        assert(is_string($this->getFormat()) || is_null($this->getFormat()));
151
        assert(is_string($this->getSPProvidedID()) || is_null($this->getSPProvidedID()));
152
        assert(is_string($this->getValue()));
153
154
        $element = parent::toXML($parent);
155
156
        if ($this->getFormat() !== null) {
157
            $element->setAttribute('Format', $this->getFormat());
158
        }
159
160
        if ($this->getSPProvidedID() !== null) {
161
            $element->setAttribute('SPProvidedID', $this->getSPProvidedID());
162
        }
163
164
        $value = $element->ownerDocument->createTextNode($this->getValue());
165
        $element->appendChild($value);
166
167
        return $element;
168
    }
169
}
170