AbstractResponseType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML11\Assert\Assert;
9
use SimpleSAML\SAML11\Type\SAMLAnyURIValue;
10
use SimpleSAML\SAML11\Type\SAMLDateTimeValue;
11
use SimpleSAML\SAML11\XML\saml\Assertion;
12
use SimpleSAML\SAML11\XML\samlp\Status;
13
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
14
use SimpleSAML\XMLSchema\Type\IDValue;
15
use SimpleSAML\XMLSchema\Type\NCNameValue;
16
use SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue;
17
18
use function strval;
19
20
/**
21
 * Base class for all SAML 1.1 samlp:AbstractResponseAbstractType.
22
 *
23
 * @package simplesamlphp/saml11
24
 */
25
abstract class AbstractResponseType extends AbstractResponseAbstractType
26
{
27
    /**
28
     * Initialize a response.
29
     *
30
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $majorVersion
31
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $minorVersion
32
     * @param \SimpleSAML\XMLSchema\Type\IDValue $id
33
     * @param \SimpleSAML\SAML11\XML\samlp\Status $status
34
     * @param array<\SimpleSAML\SAML11\XML\saml\Assertion> $assertion
35
     * @param \SimpleSAML\SAML11\Type\SAMLDateTimeValue|null $issueInstant
36
     * @param \SimpleSAML\XMLSchema\Type\NCNameValue|null $inResponseTo
37
     * @param \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null $recipient
38
     *
39
     * @throws \Exception
40
     */
41
    public function __construct(
42
        NonNegativeIntegerValue $majorVersion,
43
        NonNegativeIntegerValue $minorVersion,
44
        IDValue $id,
45
        protected Status $status,
46
        SAMLDateTimeValue $issueInstant,
47
        protected array $assertion = [],
48
        protected ?NCNameValue $inResponseTo = null,
49
        protected ?SAMLAnyURIValue $recipient = null,
50
    ) {
51
        Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class);
52
53
        parent::__construct($id, $majorVersion, $minorVersion, $issueInstant);
54
    }
55
56
57
    /**
58
     * Retrieve the inResponseTo of this message.
59
     *
60
     * @return \SimpleSAML\XMLSchema\Type\NCNameValue|null The inResponseTo of this message
61
     */
62
    public function getInResponseTo(): ?NCNameValue
63
    {
64
        return $this->inResponseTo;
65
    }
66
67
68
    /**
69
     * Retrieve the recipient of this message.
70
     *
71
     * @return \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null The recipient of this message
72
     */
73
    public function getRecipient(): ?SAMLAnyURIValue
74
    {
75
        return $this->recipient;
76
    }
77
78
79
    /**
80
     * Retrieve the assertion of this message.
81
     *
82
     * @return array<\SimpleSAML\SAML11\XML\saml\Assertion> The assertion of this message
83
     */
84
    public function getAssertion(): array
85
    {
86
        return $this->assertion;
87
    }
88
89
90
    /**
91
     * Retrieve the status of this message.
92
     *
93
     * @return \SimpleSAML\SAML11\XML\samlp\Status The status of this message
94
     */
95
    public function getStatus(): Status
96
    {
97
        return $this->status;
98
    }
99
100
101
    /**
102
     * Convert this message to an unsigned XML document.
103
     * This method does not sign the resulting XML document.
104
     *
105
     * @return \DOMElement The root element of the DOM tree
106
     */
107
    protected function toUnsignedXML(?DOMElement $parent = null): DOMElement
108
    {
109
        $e = parent::toUnsignedXML($parent);
110
111
        if ($this->getRecipient() !== null) {
112
            $e->setAttribute('Recipient', strval($this->getRecipient()));
113
        }
114
115
        if ($this->getInResponseTo() !== null) {
116
            $e->setAttribute('InResponseTo', strval($this->getInResponseTo()));
117
        }
118
119
        $this->getStatus()->toXML($e);
120
121
        foreach ($this->getAssertion() as $assertion) {
122
            $assertion->toXML($e);
123
        }
124
125
        return $e;
126
    }
127
}
128