Passed
Pull Request — master (#306)
by Tim
05:17 queued 02:42
created

UnknownRoleDescriptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 12
dl 0
loc 28
rs 9.8666
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 for unknown conditions.
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
     * Initialize a saml:RoleDescriptor from scratch
23
     *
24
     * @param \SimpleSAML\XML\Chunk $chunk The whole RoleDescriptor element as a chunk object.
25
     * @param string $type
26
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
27
     * @param string|null $ID The ID for this document. Defaults to null.
28
     * @param int|null $validUntil Unix time of validity for this document. Defaults to null.
29
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
30
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An Extensions object. Defaults to null.
31
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
32
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements. Defaults to an empty array.
33
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization The organization running this entity. Defaults to null.
34
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity. Defaults to an empty array.
35
     * @param \DOMAttr[] $namespacedAttributes
36
     */
37
    protected function __construct(
38
        Chunk $chunk,
39
        string $type,
40
        array $protocolSupportEnumeration,
41
        ?string $ID = null,
42
        ?int $validUntil = null,
43
        ?string $cacheDuration = null,
44
        ?Extensions $extensions = null,
45
        ?string $errorURL = null,
46
        array $keyDescriptors = [],
47
        ?Organization $organization = null,
48
        array $contacts = [],
49
        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

49
        /** @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...
50
    ) {
51
        parent::__construct(
52
            $type,
53
            $protocolSupportEnumeration,
54
            $ID,
55
            $validUntil,
56
            $cacheDuration,
57
            $extensions,
58
            $errorURL,
59
            $keyDescriptors,
60
            $organization,
61
            $contacts
62
        );
63
64
        $this->chunk = $chunk;
65
    }
66
67
68
    /**
69
     * Get the raw version of this RoleDescriptor as a Chunk.
70
     *
71
     * @return \SimpleSAML\XML\Chunk
72
     */
73
    public function getRawRoleDescriptor(): Chunk
74
    {
75
        return $this->chunk;
76
    }
77
78
79
    /**
80
     * Convert this unknown RoleDescriptor to XML.
81
     *
82
     * @param \DOMElement|null $parent The element we are converting to XML.
83
     * @return \DOMElement The XML element after adding the data corresponding to this unknown RoleDescriptor.
84
     */
85
    public function toXML(DOMElement $parent = null): DOMElement
86
    {
87
        return $this->chunk->toXML($parent);
88
    }
89
}
90
91