Passed
Pull Request — master (#280)
by Tim
02:13
created

AbstractSSODescriptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 13
dl 0
loc 31
rs 9.7998
c 0
b 0
f 0

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\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML2\Constants;
10
use SimpleSAML\XML\Utils as XMLUtils;
11
12
/**
13
 * Class representing SAML 2 SSODescriptorType.
14
 *
15
 * @package simplesamlphp/saml2
16
 */
17
abstract class AbstractSSODescriptor extends AbstractRoleDescriptor
18
{
19
    /**
20
     * List of ArtifactResolutionService endpoints.
21
     *
22
     * @var \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[]
23
     */
24
    protected array $artifactResolutionServiceEndpoints = [];
25
26
    /**
27
     * List of SingleLogoutService endpoints.
28
     *
29
     * @var \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
30
     */
31
    protected array $sloServiceEndpoints = [];
32
33
    /**
34
     * List of ManageNameIDService endpoints.
35
     *
36
     * @var \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
37
     */
38
    protected array $manageNameIDServiceEndpoints = [];
39
40
    /**
41
     * List of supported NameID formats.
42
     *
43
     * Array of strings.
44
     *
45
     * @var \SimpleSAML\SAML2\XML\md\NameIDFormat[]
46
     */
47
    protected array $nameIDFormats = [];
48
49
50
    /**
51
     * Initialize a RoleDescriptor.
52
     *
53
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
54
     * @param string|null $ID The ID for this document. Defaults to null.
55
     * @param int|null $validUntil Unix time of validity for this document. Defaults to null.
56
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
57
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An array of extensions. Defaults to an empty array.
58
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
59
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements.
60
     *   Defaults to an empty array.
61
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization The organization running this entity. Defaults to null.
62
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity.
63
     *   Defaults to an empty array.
64
     * @param \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[] $artifactResolutionService An array of
65
     *   ArtifactResolutionEndpoint. Defaults to an empty array.
66
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $singleLogoutService An array of SingleLogoutEndpoint.
67
     *   Defaults to an empty array.
68
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $manageNameIDService An array of ManageNameIDService.
69
     *   Defaults to an empty array.
70
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormat An array of supported NameID formats.
71
     *   Defaults to an empty array.
72
     */
73
    public function __construct(
74
        array $protocolSupportEnumeration,
75
        ?string $ID = null,
76
        ?int $validUntil = null,
77
        ?string $cacheDuration = null,
78
        ?Extensions $extensions = null,
79
        ?string $errorURL = null,
80
        array $keyDescriptors = [],
81
        ?Organization $organization = null,
82
        array $contacts = [],
83
        array $artifactResolutionService = [],
84
        array $singleLogoutService = [],
85
        array $manageNameIDService = [],
86
        array $nameIDFormat = []
87
    ) {
88
        parent::__construct(
89
            $protocolSupportEnumeration,
90
            $ID,
91
            $validUntil,
92
            $cacheDuration,
93
            $extensions,
94
            $errorURL,
95
            $keyDescriptors,
96
            $organization,
97
            $contacts
98
        );
99
100
        $this->setArtifactResolutionServices($artifactResolutionService);
101
        $this->setSingleLogoutServices($singleLogoutService);
102
        $this->setManageNameIDServices($manageNameIDService);
103
        $this->setNameIDFormats($nameIDFormat);
104
    }
105
106
107
    /**
108
     * Collect the value of the ArtifactResolutionService-property
109
     *
110
     * @return \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[]
111
     */
112
    public function getArtifactResolutionServices(): array
113
    {
114
        return $this->artifactResolutionServiceEndpoints;
115
    }
116
117
118
    /**
119
     * Set the value of the ArtifactResolutionService-property
120
     *
121
     * @param \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType[] $artifactResolutionServices
122
     * @throws \SimpleSAML\Assert\AssertionFailedException
123
     */
124
    protected function setArtifactResolutionServices(array $artifactResolutionServices): void
125
    {
126
        Assert::allIsInstanceOf(
127
            $artifactResolutionServices,
128
            ArtifactResolutionService::class,
129
            'All md:ArtifactResolutionService endpoints must be an instance of ArtifactResolutionService.'
130
        );
131
        $this->artifactResolutionServiceEndpoints = $artifactResolutionServices;
132
    }
133
134
135
    /**
136
     * Collect the value of the SingleLogoutService-property
137
     *
138
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
139
     */
140
    public function getSingleLogoutServices(): array
141
    {
142
        return $this->sloServiceEndpoints;
143
    }
144
145
146
    /**
147
     * Set the value of the SingleLogoutService-property
148
     *
149
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $singleLogoutServices
150
     * @throws \SimpleSAML\Assert\AssertionFailedException
151
     */
152
    protected function setSingleLogoutServices(array $singleLogoutServices): void
153
    {
154
        Assert::allIsInstanceOf(
155
            $singleLogoutServices,
156
            SingleLogoutService::class,
157
            'All md:SingleLogoutService endpoints must be an instance of SingleLogoutService.'
158
        );
159
        $this->sloServiceEndpoints = $singleLogoutServices;
160
    }
161
162
163
    /**
164
     * Collect the value of the ManageNameIDService-property
165
     *
166
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
167
     */
168
    public function getManageNameIDServices(): array
169
    {
170
        return $this->manageNameIDServiceEndpoints;
171
    }
172
173
174
    /**
175
     * Set the value of the ManageNameIDService-property
176
     *
177
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $manageNameIDServices
178
     * @throws \SimpleSAML\Assert\AssertionFailedException
179
     */
180
    protected function setManageNameIDServices(array $manageNameIDServices): void
181
    {
182
        Assert::allIsInstanceOf(
183
            $manageNameIDServices,
184
            ManageNameIDService::class,
185
            'All md:ManageNameIDService endpoints must be an instance of ManageNameIDService.'
186
        );
187
        $this->manageNameIDServiceEndpoints = $manageNameIDServices;
188
    }
189
190
191
    /**
192
     * Collect the value of the NameIDFormat-property
193
     *
194
     * @return \SimpleSAML\SAML2\XML\md\NameIDFormat[]
195
     */
196
    public function getNameIDFormats(): array
197
    {
198
        return $this->nameIDFormats;
199
    }
200
201
202
    /**
203
     * Set the value of the NameIDFormat-property
204
     *
205
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormats
206
     */
207
    protected function setNameIDFormats(array $nameIDFormats): void
208
    {
209
        Assert::allIsInstanceOf($nameIDFormats, NameIDFormat::class);
210
        $this->nameIDFormats = $nameIDFormats;
211
    }
212
213
214
    /**
215
     * Convert this descriptor to an unsigned XML document.
216
     * This method does not sign the resulting XML document.
217
     *
218
     * @param \DOMElement|null $parent
219
     * @return \DOMElement The root element of the DOM tree
220
     */
221
    protected function toUnsignedXML(DOMElement $parent = null): DOMElement
222
    {
223
        $e = parent::toUnsignedXML($parent);
224
225
        foreach ($this->artifactResolutionServiceEndpoints as $ep) {
226
            $ep->toXML($e);
227
        }
228
229
        foreach ($this->sloServiceEndpoints as $ep) {
230
            $ep->toXML($e);
231
        }
232
233
        foreach ($this->manageNameIDServiceEndpoints as $ep) {
234
            $ep->toXML($e);
235
        }
236
237
        foreach ($this->nameIDFormats as $nidFormat) {
238
            $nidFormat->toXML($e);
239
        }
240
241
        return $e;
242
    }
243
}
244