AbstractApplicationServiceType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

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