Passed
Pull Request — master (#306)
by Tim
02:20
created

UnknownRoleDescriptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 12
dl 0
loc 27
rs 9.9
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\XML\Chunk;
9
10
/**
11
 * Class representing unknown RoleDescriptors.
12
 *
13
 * @package simplesamlphp/saml2
14
 */
15
final class UnknownRoleDescriptor extends AbstractRoleDescriptor
16
{
17
    /** @var \SimpleSAML\XML\Chunk */
18
    protected Chunk $chunk;
19
20
21
    /**
22
     * @param \SimpleSAML\XML\Chunk $chunk The whole RoleDescriptor element as a chunk object.
23
     * @param string $type The xsi:type of this role descriptor
24
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
25
     * @param string|null $ID The ID for this document. Defaults to null.
26
     * @param int|null $validUntil Unix time of validity for this document. Defaults to null.
27
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
28
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An Extensions object. Defaults to null.
29
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
30
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements. Defaults to an empty array.
31
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization The organization running this entity. Defaults to null.
32
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity. Defaults to an empty array.
33
     * @param \DOMAttr[] $namespacedAttributes
34
     */
35
    public function __construct(
36
        Chunk $chunk,
37
        string $type,
38
        array $protocolSupportEnumeration,
39
        ?string $ID = null,
40
        ?int $validUntil = null,
41
        ?string $cacheDuration = null,
42
        ?Extensions $extensions = null,
43
        ?string $errorURL = null,
44
        array $keyDescriptors = [],
45
        ?Organization $organization = null,
46
        array $contacts = [],
47
        array $namespacedAttributes = []
0 ignored issues
show
Unused Code introduced by
The parameter $namespacedAttributes is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
        /** @scrutinizer ignore-unused */ array $namespacedAttributes = []

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    ) {
49
        parent::__construct(
50
            $protocolSupportEnumeration,
0 ignored issues
show
Bug introduced by
$protocolSupportEnumeration of type string[] is incompatible with the type string expected by parameter $type of SimpleSAML\SAML2\XML\md\...scriptor::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            /** @scrutinizer ignore-type */ $protocolSupportEnumeration,
Loading history...
51
            $ID,
0 ignored issues
show
Bug introduced by
$ID of type null|string is incompatible with the type array expected by parameter $protocolSupportEnumeration of SimpleSAML\SAML2\XML\md\...scriptor::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
            /** @scrutinizer ignore-type */ $ID,
Loading history...
52
            $validUntil,
53
            $cacheDuration,
0 ignored issues
show
Bug introduced by
It seems like $cacheDuration can also be of type string; however, parameter $validUntil of SimpleSAML\SAML2\XML\md\...scriptor::__construct() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
            /** @scrutinizer ignore-type */ $cacheDuration,
Loading history...
54
            $extensions,
55
            $errorURL,
0 ignored issues
show
Bug introduced by
It seems like $errorURL can also be of type string; however, parameter $extensions of SimpleSAML\SAML2\XML\md\...scriptor::__construct() does only seem to accept SimpleSAML\SAML2\XML\md\Extensions|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
            /** @scrutinizer ignore-type */ $errorURL,
Loading history...
56
            $keyDescriptors,
0 ignored issues
show
Bug introduced by
$keyDescriptors of type SimpleSAML\SAML2\XML\md\KeyDescriptor[]|array is incompatible with the type null|string expected by parameter $errorURL of SimpleSAML\SAML2\XML\md\...scriptor::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
            /** @scrutinizer ignore-type */ $keyDescriptors,
Loading history...
57
            $organization,
0 ignored issues
show
Bug introduced by
$organization of type SimpleSAML\SAML2\XML\md\Organization|null is incompatible with the type array expected by parameter $keyDescriptors of SimpleSAML\SAML2\XML\md\...scriptor::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            /** @scrutinizer ignore-type */ $organization,
Loading history...
58
            $contacts
0 ignored issues
show
Bug introduced by
$contacts of type SimpleSAML\SAML2\XML\md\ContactPerson[]|array is incompatible with the type SimpleSAML\SAML2\XML\md\Organization|null expected by parameter $organization of SimpleSAML\SAML2\XML\md\...scriptor::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
            /** @scrutinizer ignore-type */ $contacts
Loading history...
59
        );
60
61
        $this->chunk = $chunk;
62
    }
63
64
65
    /**
66
     * Get the raw version of this role descriptor as a Chunk.
67
     *
68
     * @return \SimpleSAML\XML\Chunk
69
     */
70
    public function getRawRoleDescriptor(): Chunk
71
    {
72
        return $this->chunk;
73
    }
74
75
76
    /**
77
     * Convert this unknown role descriptor to XML.
78
     *
79
     * @param \DOMElement|null $parent The element we are converting to XML.
80
     * @return \DOMElement The XML element after adding the data corresponding to this unknown role descriptor.
81
     */
82
    public function toXML(DOMElement $parent = null): DOMElement
83
    {
84
        return $this->chunk->toXML($parent);
85
    }
86
}
87