Passed
Pull Request — master (#306)
by Tim
03:01
created

UnknownRoleDescriptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 12
dl 0
loc 29
rs 9.8333

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 = []
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
            $namespacedAttributes
63
        );
64
65
        $this->chunk = $chunk;
66
    }
67
68
69
    /**
70
     * Get the raw version of this RoleDescriptor as a Chunk.
71
     *
72
     * @return \SimpleSAML\XML\Chunk
73
     */
74
    public function getRawRoleDescriptor(): Chunk
75
    {
76
        return $this->chunk;
77
    }
78
79
80
    /**
81
     * Convert this unknown RoleDescriptor to XML.
82
     *
83
     * @param \DOMElement|null $parent The element we are converting to XML.
84
     * @return \DOMElement The XML element after adding the data corresponding to this unknown RoleDescriptor.
85
     */
86
    public function toXML(DOMElement $parent = null): DOMElement
87
    {
88
        return $this->chunk->toXML($parent);
89
    }
90
}
91
92