AbstractAttributeServiceType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 56
rs 9.44
cc 1
nc 1
nop 21

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 AttributeServiceType
18
 *
19
 * @package simplesamlphp/ws-security
20
 */
21
abstract class AbstractAttributeServiceType extends AbstractWebServiceDescriptorType
22
{
23
    /** @var string */
24
    public const XSI_TYPE_PREFIX = 'fed';
25
26
    /** @var string */
27
    public const XSI_TYPE_NAME = 'AttributeServiceType';
28
29
    /** @var string */
30
    public const XSI_TYPE_NAMESPACE = C::NS_FED;
31
32
33
    /**
34
     * AttributeServiceType 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[] $keyDescriptor 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[] $contact 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\AttributeServiceEndpoint[] $attributeServiceEndpoint
59
     * @param \SimpleSAML\WSSecurity\XML\fed\SingleSignOutNotificationEndpoint[] $singleSignOutNotificationEndpoint
60
     */
61
    final public function __construct(
62
        array $protocolSupportEnumeration,
63
        ?string $ID = null,
64
        ?DateTimeImmutable $validUntil = null,
65
        ?string $cacheDuration = null,
66
        ?Extensions $extensions = null,
67
        ?string $errorURL = null,
68
        array $keyDescriptor = [],
69
        ?Organization $organization = null,
70
        array $contact = [],
71
        array $namespacedAttributes = [],
72
        ?LogicalServiceNamesOffered $logicalServiceNamesOffered = null,
73
        ?TokenTypesOffered $tokenTypesOffered = null,
74
        ?ClaimDialectsOffered $claimDialectsOffered = null,
75
        ?ClaimTypesOffered $claimTypesOffered = null,
76
        ?ClaimTypesRequested $claimTypesRequested = null,
77
        ?AutomaticPseudonyms $automaticPseudonyms = null,
78
        ?TargetScopes $targetScopes = null,
79
        ?string $serviceDisplayName = null,
80
        ?string $serviceDescription = null,
81
        protected array $attributeServiceEndpoint = [],
82
        protected array $singleSignOutNotificationEndpoint = [],
83
    ) {
84
        Assert::minCount($attributeServiceEndpoint, 1, MissingElementException::class);
85
        Assert::allIsInstanceOf(
86
            $attributeServiceEndpoint,
87
            AttributeServiceEndpoint::class,
88
            SchemaViolationException::class,
89
        );
90
        Assert::allIsInstanceOf(
91
            $singleSignOutNotificationEndpoint,
92
            SingleSignOutNotificationEndpoint::class,
93
            SchemaViolationException::class,
94
        );
95
96
        parent::__construct(
97
            static::XSI_TYPE_PREFIX . ':' . static::XSI_TYPE_NAME,
98
            $protocolSupportEnumeration,
99
            $ID,
100
            $validUntil,
101
            $cacheDuration,
102
            $extensions,
103
            $errorURL,
104
            $keyDescriptor,
105
            $organization,
106
            $contact,
107
            $namespacedAttributes,
108
            $logicalServiceNamesOffered,
109
            $tokenTypesOffered,
110
            $claimDialectsOffered,
111
            $claimTypesOffered,
112
            $claimTypesRequested,
113
            $automaticPseudonyms,
114
            $targetScopes,
115
            $serviceDisplayName,
116
            $serviceDescription,
117
        );
118
    }
119
120
121
    /**
122
     * Collect the value of the attributeServicEndpoint-property
123
     *
124
     * @return \SimpleSAML\WSSecurity\XML\fed\AttributeServiceEndpoint[]
125
     */
126
    public function getAttributeServiceEndpoint(): array
127
    {
128
        return $this->attributeServiceEndpoint;
129
    }
130
131
132
    /**
133
     * Collect the value of the singleSignOutNotificationtionEndpoint-property
134
     *
135
     * @return \SimpleSAML\WSSecurity\XML\fed\SingleSignOutNotificationEndpoint[]
136
     */
137
    public function getSingleSignOutNotificationEndpoint(): array
138
    {
139
        return $this->singleSignOutNotificationEndpoint;
140
    }
141
142
143
    /**
144
     * Convert this element to XML.
145
     *
146
     * @param \DOMElement|null $parent The element we should append this element to.
147
     * @return \DOMElement
148
     */
149
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
150
    {
151
        $e = parent::toXML($parent);
152
153
        foreach ($this->getAttributeServiceEndpoint() as $ase) {
154
            $ase->toXML($e);
155
        }
156
157
        foreach ($this->getSingleSignOutNotificationEndpoint() as $ssone) {
158
            $ssone->toXML($e);
159
        }
160
161
        return $e;
162
    }
163
}
164