AuthnRequest   A
last analyzed

Complexity

Total Complexity 34

Size/Duplication

Total Lines 313
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 1

Test Coverage

Coverage 97.47%

Importance

Changes 0
Metric Value
dl 0
loc 313
c 0
b 0
f 0
wmc 34
lcom 4
cbo 1
ccs 77
cts 79
cp 0.9747
rs 9.68

24 Methods

Rating   Name   Duplication   Size   Complexity  
A setSubject() 0 6 1
A getSubject() 0 4 1
A setProviderName() 0 6 1
A getProviderName() 0 4 1
A setProtocolBinding() 0 6 1
A getProtocolBinding() 0 4 1
A setNameIDPolicy() 0 6 1
A getNameIDPolicy() 0 4 1
A setIsPassive() 0 6 3
A getIsPassive() 0 4 1
A getIsPassiveString() 0 8 3
A setForceAuthn() 0 6 3
A getForceAuthn() 0 4 1
A getForceAuthnString() 0 8 3
A setConditions() 0 6 1
A getConditions() 0 4 1
A setAttributeConsumingServiceIndex() 0 8 2
A getAttributeConsumingServiceIndex() 0 4 1
A setAssertionConsumerServiceURL() 0 6 1
A getAssertionConsumerServiceURL() 0 4 1
A setAssertionConsumerServiceIndex() 0 8 2
A getAssertionConsumerServiceIndex() 0 4 1
A serialize() 0 16 1
A deserialize() 0 17 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Model\Protocol;
13
14
use LightSaml\Model\Context\DeserializationContext;
15
use LightSaml\Model\Context\SerializationContext;
16
use LightSaml\Model\Assertion\Conditions;
17
use LightSaml\Model\Assertion\Subject;
18
use LightSaml\SamlConstants;
19
20
class AuthnRequest extends AbstractRequest
21
{
22
    //region Attributes
23
24
    /** @var bool|null */
25
    protected $forceAuthn;
26
27
    /** @var bool|null */
28
    protected $isPassive;
29
30
    /** @var int|null */
31
    protected $assertionConsumerServiceIndex;
32
33
    /** @var string|null */
34
    protected $assertionConsumerServiceURL;
35
36
    /** @var int|null */
37
    protected $attributeConsumingServiceIndex;
38
39
    /** @var string|null */
40
    protected $protocolBinding;
41
42
    /** @var string|null */
43
    protected $providerName;
44
45
    //endregion
46
47
    //region Elements
48
49
    /** @var Conditions|null */
50
    protected $conditions;
51
52
    /** @var NameIDPolicy|null */
53
    protected $nameIDPolicy;
54
55
    /** @var Subject|null */
56
    protected $subject;
57
58
    /**
59
     * @param Subject|null $subject
60
     *
61
     * @return AuthnRequest
62
     */
63 1
    public function setSubject(Subject $subject)
64
    {
65 1
        $this->subject = $subject;
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * @return Subject|null
72
     */
73 10
    public function getSubject()
74
    {
75 10
        return $this->subject;
76
    }
77
78
    /**
79
     * @param null|string $providerName
80
     *
81
     * @return AuthnRequest
82
     */
83 1
    public function setProviderName($providerName)
84
    {
85 1
        $this->providerName = (string) $providerName;
86
87 1
        return $this;
88
    }
89
90
    /**
91
     * @return null|string
92
     */
93 10
    public function getProviderName()
94
    {
95 10
        return $this->providerName;
96
    }
97
98
    /**
99
     * @param null|string $protocolBinding
100
     *
101
     * @return AuthnRequest
102
     */
103 3
    public function setProtocolBinding($protocolBinding)
104
    {
105 3
        $this->protocolBinding = (string) $protocolBinding;
106
107 3
        return $this;
108
    }
109
110
    /**
111
     * @return null|string
112
     */
113 10
    public function getProtocolBinding()
114
    {
115 10
        return $this->protocolBinding;
116
    }
117
118
    /**
119
     * @param NameIDPolicy|null $nameIDPolicy
120
     *
121
     * @return AuthnRequest
122
     */
123 4
    public function setNameIDPolicy(NameIDPolicy $nameIDPolicy)
124
    {
125 4
        $this->nameIDPolicy = $nameIDPolicy;
126
127 4
        return $this;
128
    }
129
130
    /**
131
     * @return NameIDPolicy|null
132
     */
133 10
    public function getNameIDPolicy()
134
    {
135 10
        return $this->nameIDPolicy;
136
    }
137
138
    /**
139
     * @param bool|null $isPassive
140
     *
141
     * @return AuthnRequest
142
     */
143 1
    public function setIsPassive($isPassive)
144
    {
145 1
        $this->isPassive = 0 == strcasecmp($isPassive, 'true') || true === $isPassive || 1 == $isPassive;
146
147 1
        return $this;
148
    }
149
150
    /**
151
     * @return bool|null
152
     */
153 1
    public function getIsPassive()
154
    {
155 1
        return $this->isPassive;
156
    }
157
158
    /**
159
     * @return string|null
160
     */
161 10
    public function getIsPassiveString()
162
    {
163 10
        if (null === $this->isPassive) {
164 9
            return null;
165
        }
166
167 1
        return $this->isPassive ? 'true' : 'false';
168
    }
169
170
    /**
171
     * @param bool|null $forceAuthn
172
     *
173
     * @return AuthnRequest
174
     */
175 1
    public function setForceAuthn($forceAuthn)
176
    {
177 1
        $this->forceAuthn = 0 == strcasecmp($forceAuthn, 'true') || true === $forceAuthn || 1 == $forceAuthn;
178
179 1
        return $this;
180
    }
181
182
    /**
183
     * @return bool|null
184
     */
185 1
    public function getForceAuthn()
186
    {
187 1
        return $this->forceAuthn;
188
    }
189
190
    /**
191
     * @return string|null
192
     */
193 10
    public function getForceAuthnString()
194
    {
195 10
        if (null === $this->forceAuthn) {
196 9
            return null;
197
        }
198
199 1
        return $this->forceAuthn ? 'true' : 'false';
200
    }
201
202
    /**
203
     * @param Conditions|null $conditions
204
     *
205
     * @return AuthnRequest
206
     */
207 1
    public function setConditions($conditions)
208
    {
209 1
        $this->conditions = $conditions;
210
211 1
        return $this;
212
    }
213
214
    /**
215
     * @return \LightSaml\Model\Assertion\Conditions|null
216
     */
217 10
    public function getConditions()
218
    {
219 10
        return $this->conditions;
220
    }
221
222
    /**
223
     * @param null|int $attributeConsumingServiceIndex
224
     *
225
     * @return AuthnRequest
226
     */
227 1
    public function setAttributeConsumingServiceIndex($attributeConsumingServiceIndex)
228
    {
229 1
        $this->attributeConsumingServiceIndex = null !== $attributeConsumingServiceIndex
230 1
            ? intval(((string) $attributeConsumingServiceIndex))
231
            : null;
232
233 1
        return $this;
234
    }
235
236
    /**
237
     * @return null|int
238
     */
239 10
    public function getAttributeConsumingServiceIndex()
240
    {
241 10
        return $this->attributeConsumingServiceIndex;
242
    }
243
244
    /**
245
     * @param null|string $assertionConsumerServiceURL
246
     *
247
     * @return AuthnRequest
248
     */
249 6
    public function setAssertionConsumerServiceURL($assertionConsumerServiceURL)
250
    {
251 6
        $this->assertionConsumerServiceURL = (string) $assertionConsumerServiceURL;
252
253 6
        return $this;
254
    }
255
256
    /**
257
     * @return null|string
258
     */
259 18
    public function getAssertionConsumerServiceURL()
260
    {
261 18
        return $this->assertionConsumerServiceURL;
262
    }
263
264
    /**
265
     * @param null|int $assertionConsumerServiceIndex
266
     *
267
     * @return AuthnRequest
268
     */
269 2
    public function setAssertionConsumerServiceIndex($assertionConsumerServiceIndex)
270
    {
271 2
        $this->assertionConsumerServiceIndex = null !== $assertionConsumerServiceIndex
272 2
            ? intval((string) $assertionConsumerServiceIndex)
273
            : null;
274
275 2
        return $this;
276
    }
277
278
    /**
279
     * @return null|int
280
     */
281 17
    public function getAssertionConsumerServiceIndex()
282
    {
283 17
        return $this->assertionConsumerServiceIndex;
284
    }
285
286
    //endregion
287
288
    /**
289
     * @param \DOMNode             $parent
290
     * @param SerializationContext $context
291
     *
292
     * @return void
293
     */
294 9
    public function serialize(\DOMNode $parent, SerializationContext $context)
295
    {
296 9
        $result = $this->createElement('AuthnRequest', SamlConstants::NS_PROTOCOL, $parent, $context);
297
298 9
        parent::serialize($result, $context);
299
300 9
        $this->attributesToXml(array(
301 9
                'ForceAuthn', 'IsPassive', 'ProtocolBinding', 'AssertionConsumerServiceIndex',
302
                'AssertionConsumerServiceURL', 'AttributeConsumingServiceIndex', 'ProviderName',
303 9
            ), $result);
304
305 9
        $this->singleElementsToXml(array('Subject', 'NameIDPolicy', 'Conditions'), $result, $context);
306
307
        // must be last in order signature to include them all
308 9
        $this->singleElementsToXml(array('Signature'), $result, $context);
309 9
    }
310
311
    /**
312
     * @param \DOMNode               $node
313
     * @param DeserializationContext $context
314
     */
315 8
    public function deserialize(\DOMNode $node, DeserializationContext $context)
316
    {
317 8
        $this->checkXmlNodeName($node, 'AuthnRequest', SamlConstants::NS_PROTOCOL);
318
319 8
        parent::deserialize($node, $context);
320
321 8
        $this->attributesFromXml($node, array(
0 ignored issues
show
Compatibility introduced by
$node of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
322 8
            'ForceAuthn', 'IsPassive', 'ProtocolBinding', 'AssertionConsumerServiceIndex',
323
            'AssertionConsumerServiceURL', 'AttributeConsumingServiceIndex', 'ProviderName',
324
        ));
325
326 8
        $this->singleElementsFromXml($node, $context, array(
0 ignored issues
show
Compatibility introduced by
$node of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
327 8
            'Subject' => array('saml', 'LightSaml\Model\Assertion\Subject'),
328
            'NameIDPolicy' => array('samlp', 'LightSaml\Model\Protocol\NameIDPolicy'),
329
            'Conditions' => array('saml', 'LightSaml\Model\Assertion\Conditions'),
330
        ));
331 8
    }
332
}
333