AbstractSecurityTokenServiceType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 68
rs 9.312
cc 1
nc 1
nop 23

How to fix   Long Method    Many Parameters   

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:

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\WSSecurity\XML\fed;
6
7
use DateTimeImmutable;
8
use DOMElement;
9
use SimpleSAML\SAML2\XML\md\Extensions;
10
use SimpleSAML\SAML2\XML\md\Organization;
11
use SimpleSAML\WSSecurity\Assert\Assert;
12
use SimpleSAML\WSSecurity\Constants as C;
13
use SimpleSAML\XML\Exception\MissingElementException;
14
use SimpleSAML\XML\Exception\SchemaViolationException;
15
16
/**
17
 * A SecurityTokenServiceType
18
 *
19
 * @package simplesamlphp/ws-security
20
 */
21
abstract class AbstractSecurityTokenServiceType extends AbstractWebServiceDescriptorType
22
{
23
    /** @var string */
24
    public const XSI_TYPE_PREFIX = 'fed';
25
26
    /** @var string */
27
    public const XSI_TYPE_NAME = 'SecurityTokenServiceType';
28
29
    /** @var string */
30
    public const XSI_TYPE_NAMESPACE = C::NS_FED;
31
32
33
    /**
34
     * SecurityTokenServiceType constructor.
35
     *
36
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
37
     * @param string|null $ID The ID for this document. Defaults to null.
38
     * @param \DateTimeImmutable|null $validUntil Unix time of validity for this document. Defaults to null.
39
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
40
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An array of extensions. Defaults to an empty array.
41
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
42
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements.
43
     *   Defaults to an empty array.
44
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
45
     *   The organization running this entity. Defaults to null.
46
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity.
47
     *   Defaults to an empty array.
48
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\fed\list 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...
49
     * @param \SimpleSAML\WSSecurity\XML\fed\LogicalServiceNamesOffered|null $logicalServiceNamesOffered
50
     * @param \SimpleSAML\WSSecurity\XML\fed\TokenTypesOffered|null $tokenTypesOffered
51
     * @param \SimpleSAML\WSSecurity\XML\fed\ClaimDialectsOffered|null $claimDialectsOffered
52
     * @param \SimpleSAML\WSSecurity\XML\fed\ClaimTypesOffered|null $claimTypesOffered
53
     * @param \SimpleSAML\WSSecurity\XML\fed\ClaimTypesRequested|null $claimTypesRequested
54
     * @param \SimpleSAML\WSSecurity\XML\fed\AutomaticPseudonyms|null $automaticPseudonyms
55
     * @param \SimpleSAML\WSSecurity\XML\fed\TargetScopes|null $targetScopes
56
     * @param string|null $serviceDisplayName
57
     * @param string|null $serviceDescription
58
     * @param \SimpleSAML\WSSecurity\XML\fed\SecurityTokenServiceEndpoint[] $securityTokenServiceEndpoint
59
     * @param \SimpleSAML\WSSecurity\XML\fed\SingleSignOutSubscriptionEndpoint[] $singleSignOutSubscriptionEndpoint
60
     * @param \SimpleSAML\WSSecurity\XML\fed\SingleSignOutNotificationEndpoint[] $singleSignOutNotificationEndpoint
61
     * @param \SimpleSAML\WSSecurity\XML\fed\PassiveRequestorEndpoint[] $passiveRequestorEndpoint
62
     */
63
    final public function __construct(
64
        array $protocolSupportEnumeration,
65
        ?string $ID = null,
66
        ?DateTimeImmutable $validUntil = null,
67
        ?string $cacheDuration = null,
68
        ?Extensions $extensions = null,
69
        ?string $errorURL = null,
70
        array $keyDescriptors = [],
71
        ?Organization $organization = null,
72
        array $contacts = [],
73
        array $namespacedAttributes = [],
74
        ?LogicalServiceNamesOffered $logicalServiceNamesOffered = null,
75
        ?TokenTypesOffered $tokenTypesOffered = null,
76
        ?ClaimDialectsOffered $claimDialectsOffered = null,
77
        ?ClaimTypesOffered $claimTypesOffered = null,
78
        ?ClaimTypesRequested $claimTypesRequested = null,
79
        ?AutomaticPseudonyms $automaticPseudonyms = null,
80
        ?TargetScopes $targetScopes = null,
81
        ?string $serviceDisplayName = null,
82
        ?string $serviceDescription = null,
83
        protected array $securityTokenServiceEndpoint = [],
84
        protected array $singleSignOutSubscriptionEndpoint = [],
85
        protected array $singleSignOutNotificationEndpoint = [],
86
        protected array $passiveRequestorEndpoint = [],
87
    ) {
88
        Assert::minCount($securityTokenServiceEndpoint, 1, MissingElementException::class);
89
        Assert::allIsInstanceOf(
90
            $securityTokenServiceEndpoint,
91
            SecurityTokenServiceEndpoint::class,
92
            SchemaViolationException::class,
93
        );
94
        Assert::allIsInstanceOf(
95
            $singleSignOutSubscriptionEndpoint,
96
            SingleSignOutSubscriptionEndpoint::class,
97
            SchemaViolationException::class,
98
        );
99
        Assert::allIsInstanceOf(
100
            $singleSignOutNotificationEndpoint,
101
            SingleSignOutNotificationEndpoint::class,
102
            SchemaViolationException::class,
103
        );
104
        Assert::allIsInstanceOf(
105
            $passiveRequestorEndpoint,
106
            PassiveRequestorEndpoint::class,
107
            SchemaViolationException::class,
108
        );
109
110
        parent::__construct(
111
            static::XSI_TYPE_PREFIX . ':' . static::XSI_TYPE_NAME,
112
            $protocolSupportEnumeration,
113
            $ID,
114
            $validUntil,
115
            $cacheDuration,
116
            $extensions,
117
            $errorURL,
118
            $keyDescriptors,
119
            $organization,
120
            $contacts,
121
            $namespacedAttributes,
122
            $logicalServiceNamesOffered,
123
            $tokenTypesOffered,
124
            $claimDialectsOffered,
125
            $claimTypesOffered,
126
            $claimTypesRequested,
127
            $automaticPseudonyms,
128
            $targetScopes,
129
            $serviceDisplayName,
130
            $serviceDescription,
131
        );
132
    }
133
134
135
    /**
136
     * Collect the value of the securityTokenServiceEndpoint-property
137
     *
138
     * @return \SimpleSAML\WSSecurity\XML\fed\SecurityTokenServiceEndpoint[]
139
     */
140
    public function getSecurityTokenServiceEndpoint(): array
141
    {
142
        return $this->securityTokenServiceEndpoint;
143
    }
144
145
146
    /**
147
     * Collect the value of the singleSignOutSubscriptionEndpoint-property
148
     *
149
     * @return \SimpleSAML\WSSecurity\XML\fed\SingleSignOutSubscriptionEndpoint[]
150
     */
151
    public function getSingleSignOutSubscriptionEndpoint(): array
152
    {
153
        return $this->singleSignOutSubscriptionEndpoint;
154
    }
155
156
157
    /**
158
     * Collect the value of the singleSignOutNotificationtionEndpoint-property
159
     *
160
     * @return \SimpleSAML\WSSecurity\XML\fed\SingleSignOutNotificationEndpoint[]
161
     */
162
    public function getSingleSignOutNotificationEndpoint(): array
163
    {
164
        return $this->singleSignOutNotificationEndpoint;
165
    }
166
167
168
    /**
169
     * Collect the value of the passiveRequestorEndpoint-property
170
     *
171
     * @return \SimpleSAML\WSSecurity\XML\fed\PassiveRequestorEndpoint[]
172
     */
173
    public function getPassiveRequestorEndpoint(): array
174
    {
175
        return $this->passiveRequestorEndpoint;
176
    }
177
178
179
    /**
180
     * Convert this element to XML.
181
     *
182
     * @param \DOMElement|null $parent The element we should append this element to.
183
     * @return \DOMElement
184
     */
185
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
186
    {
187
        $e = parent::toUnsignedXML($parent);
188
189
        foreach ($this->getSecurityTokenServiceEndpoint() as $stse) {
190
            $stse->toXML($e);
191
        }
192
193
        foreach ($this->getSingleSignOutSubscriptionEndpoint() as $ssose) {
194
            $ssose->toXML($e);
195
        }
196
197
        foreach ($this->getSingleSignOutNotificationEndpoint() as $ssone) {
198
            $ssone->toXML($e);
199
        }
200
201
        foreach ($this->getPassiveRequestorEndpoint() as $pre) {
202
            $pre->toXML($e);
203
        }
204
205
        return $e;
206
    }
207
}
208