Passed
Pull Request — master (#280)
by Tim
02:26
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
160
        $this->sloServiceEndpoints = $singleLogoutServices;
161
    }
162
163
164
    /**
165
     * Collect the value of the ManageNameIDService-property
166
     *
167
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
168
     */
169
    public function getManageNameIDServices(): array
170
    {
171
        return $this->manageNameIDServiceEndpoints;
172
    }
173
174
175
    /**
176
     * Set the value of the ManageNameIDService-property
177
     *
178
     * @param \SimpleSAML\SAML2\XML\md\AbstractEndpointType[] $manageNameIDServices
179
     * @throws \SimpleSAML\Assert\AssertionFailedException
180
     */
181
    protected function setManageNameIDServices(array $manageNameIDServices): void
182
    {
183
        Assert::allIsInstanceOf(
184
            $manageNameIDServices,
185
            ManageNameIDService::class,
186
            'All md:ManageNameIDService endpoints must be an instance of ManageNameIDService.'
187
        );
188
189
        $this->manageNameIDServiceEndpoints = $manageNameIDServices;
190
    }
191
192
193
    /**
194
     * Collect the value of the NameIDFormat-property
195
     *
196
     * @return \SimpleSAML\SAML2\XML\md\NameIDFormat[]
197
     */
198
    public function getNameIDFormats(): array
199
    {
200
        return $this->nameIDFormats;
201
    }
202
203
204
    /**
205
     * Set the value of the NameIDFormat-property
206
     *
207
     * @param \SimpleSAML\SAML2\XML\md\NameIDFormat[] $nameIDFormats
208
     */
209
    protected function setNameIDFormats(array $nameIDFormats): void
210
    {
211
        Assert::allIsInstanceOf($nameIDFormats, NameIDFormat::class, ProtocolViolationException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\ProtocolViolationException 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...
212
        $this->nameIDFormats = $nameIDFormats;
213
    }
214
215
216
    /**
217
     * Convert this descriptor to an unsigned XML document.
218
     * This method does not sign the resulting XML document.
219
     *
220
     * @param \DOMElement|null $parent
221
     * @return \DOMElement The root element of the DOM tree
222
     */
223
    protected function toUnsignedXML(DOMElement $parent = null): DOMElement
224
    {
225
        $e = parent::toUnsignedXML($parent);
226
227
        foreach ($this->artifactResolutionServiceEndpoints as $ep) {
228
            $ep->toXML($e);
229
        }
230
231
        foreach ($this->sloServiceEndpoints as $ep) {
232
            $ep->toXML($e);
233
        }
234
235
        foreach ($this->manageNameIDServiceEndpoints as $ep) {
236
            $ep->toXML($e);
237
        }
238
239
        foreach ($this->nameIDFormats as $nidFormat) {
240
            $nidFormat->toXML($e);
241
        }
242
243
        return $e;
244
    }
245
}
246