AuthnAuthorityDescriptor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 24
nc 1
nop 13
dl 0
loc 42
rs 9.536
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\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Type\SAMLAnyURIListValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Type\SAMLAnyURIListValue 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...
10
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
11
use SimpleSAML\SAML2\Type\SAMLDateTimeValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Type\SAMLDateTimeValue 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...
12
use SimpleSAML\XML\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\Constants 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...
13
use SimpleSAML\XML\SchemaValidatableElementInterface;
14
use SimpleSAML\XML\SchemaValidatableElementTrait;
15
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
16
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
17
use SimpleSAML\XMLSchema\Type\DurationValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\DurationValue 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...
18
use SimpleSAML\XMLSchema\Type\IDValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\IDValue 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...
19
use SimpleSAML\XMLSecurity\XML\ds\Signature;
20
21
/**
22
 * Class representing SAML 2 metadata AuthnAuthorityDescriptor.
23
 *
24
 * @package simplesamlphp/saml2
25
 */
26
final class AuthnAuthorityDescriptor extends AbstractRoleDescriptorType implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType 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...
27
{
28
    use SchemaValidatableElementTrait;
29
30
31
    /**
32
     * AuthnAuthorityDescriptor constructor.
33
     *
34
     * @param array $authnQueryService
35
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIListValue $protocolSupportEnumeration
36
     * @param array $assertionIDRequestService
37
     * @param array $nameIDFormat
38
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $ID
39
     * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null $validUntil
40
     * @param \SimpleSAML\XMLSchema\Type\DurationValue|null $cacheDuration
41
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions
42
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $errorURL
43
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
44
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptor
45
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contact
46
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\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...
47
     */
48
    public function __construct(
49
        protected array $authnQueryService,
50
        SAMLAnyURIListValue $protocolSupportEnumeration,
51
        protected array $assertionIDRequestService = [],
52
        protected array $nameIDFormat = [],
53
        ?IDValue $ID = null,
54
        ?SAMLDateTimeValue $validUntil = null,
55
        ?DurationValue $cacheDuration = null,
56
        ?Extensions $extensions = null,
57
        ?SAMLAnyURIValue $errorURL = null,
58
        ?Organization $organization = null,
59
        array $keyDescriptor = [],
60
        array $contact = [],
61
        array $namespacedAttributes = [],
62
    ) {
63
        Assert::maxCount($authnQueryService, C::UNBOUNDED_LIMIT);
64
        Assert::minCount($authnQueryService, 1, 'Missing at least one AuthnQueryService in AuthnAuthorityDescriptor.');
65
        Assert::allIsInstanceOf(
66
            $authnQueryService,
67
            AbstractEndpointType::class,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\AbstractEndpointType 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...
68
            'AuthnQueryService must be an instance of EndpointType',
69
        );
70
        Assert::maxCount($assertionIDRequestService, C::UNBOUNDED_LIMIT);
71
        Assert::allIsInstanceOf(
72
            $assertionIDRequestService,
73
            AbstractEndpointType::class,
74
            'AssertionIDRequestServices must be an instance of EndpointType',
75
        );
76
        Assert::maxCount($nameIDFormat, C::UNBOUNDED_LIMIT);
77
        Assert::allIsInstanceOf($nameIDFormat, NameIDFormat::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\NameIDFormat 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...
78
79
        parent::__construct(
80
            $protocolSupportEnumeration,
81
            $ID,
82
            $validUntil,
83
            $cacheDuration,
84
            $extensions,
85
            $errorURL,
86
            $keyDescriptor,
87
            $organization,
88
            $contact,
89
            $namespacedAttributes,
90
        );
91
    }
92
93
94
    /**
95
     * Collect the AuthnQueryService endpoints
96
     *
97
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
98
     */
99
    public function getAuthnQueryService(): array
100
    {
101
        return $this->authnQueryService;
102
    }
103
104
105
    /**
106
     * Collect the AssertionIDRequestService endpoints
107
     *
108
     * @return \SimpleSAML\SAML2\XML\md\AbstractEndpointType[]
109
     */
110
    public function getAssertionIDRequestService(): array
111
    {
112
        return $this->assertionIDRequestService;
113
    }
114
115
116
    /**
117
     * Collect the values of the NameIDFormat
118
     *
119
     * @return \SimpleSAML\SAML2\XML\md\NameIDFormat[]
120
     */
121
    public function getNameIDFormat(): array
122
    {
123
        return $this->nameIDFormat;
124
    }
125
126
127
    /**
128
     * Initialize an IDPSSODescriptor from an existing XML document.
129
     *
130
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
131
     *   if the qualified name of the supplied element is wrong
132
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
133
     *   if the supplied element is missing one of the mandatory attributes
134
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
135
     *   if too many child-elements of a type are specified
136
     */
137
    public static function fromXML(DOMElement $xml): static
138
    {
139
        Assert::same($xml->localName, 'AuthnAuthorityDescriptor', InvalidDOMElementException::class);
140
        Assert::same($xml->namespaceURI, AuthnAuthorityDescriptor::NS, InvalidDOMElementException::class);
141
142
        $authnQueryServices = AuthnQueryService::getChildrenOfClass($xml);
143
        $assertionIDRequestServices = AssertionIDRequestService::getChildrenOfClass($xml);
144
        $nameIDFormats = NameIDFormat::getChildrenOfClass($xml);
145
146
        $orgs = Organization::getChildrenOfClass($xml);
147
        Assert::maxCount(
148
            $orgs,
149
            1,
150
            'More than one Organization found in this descriptor',
151
            TooManyElementsException::class,
152
        );
153
154
        $extensions = Extensions::getChildrenOfClass($xml);
155
        Assert::maxCount(
156
            $extensions,
157
            1,
158
            'Only one md:Extensions element is allowed.',
159
            TooManyElementsException::class,
160
        );
161
162
        $signature = Signature::getChildrenOfClass($xml);
163
        Assert::maxCount(
164
            $signature,
165
            1,
166
            'Only one ds:Signature element is allowed.',
167
            TooManyElementsException::class,
168
        );
169
170
        $authority = new static(
171
            $authnQueryServices,
172
            self::getAttribute($xml, 'protocolSupportEnumeration', SAMLAnyURIListValue::class),
173
            $assertionIDRequestServices,
174
            $nameIDFormats,
175
            self::getOptionalAttribute($xml, 'ID', IDValue::class, null),
176
            self::getOptionalAttribute($xml, 'validUntil', SAMLDateTimeValue::class, null),
177
            self::getOptionalAttribute($xml, 'cacheDuration', DurationValue::class, null),
178
            !empty($extensions) ? $extensions[0] : null,
179
            self::getOptionalAttribute($xml, 'errorURL', SAMLAnyURIValue::class, null),
180
            !empty($orgs) ? $orgs[0] : null,
181
            KeyDescriptor::getChildrenOfClass($xml),
182
            ContactPerson::getChildrenOfClass($xml),
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\ContactPerson 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...
183
            self::getAttributesNSFromXML($xml),
184
        );
185
186
        if (!empty($signature)) {
187
            $authority->setSignature($signature[0]);
188
            $authority->setXML($xml);
189
        }
190
191
        return $authority;
192
    }
193
194
195
    /**
196
     * Add this IDPSSODescriptor to an EntityDescriptor.
197
     *
198
     * @throws \Exception
199
     */
200
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
201
    {
202
        $e = parent::toUnsignedXML($parent);
203
204
        foreach ($this->getAuthnQueryService() as $ep) {
205
            $ep->toXML($e);
206
        }
207
208
        foreach ($this->getAssertionIDRequestService() as $ep) {
209
            $ep->toXML($e);
210
        }
211
212
        foreach ($this->getNameIDFormat() as $nidFormat) {
213
            $nidFormat->toXML($e);
214
        }
215
216
        return $e;
217
    }
218
}
219