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

UnknownRoleDescriptor::fromXML()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 24
nc 1
nop 1
dl 0
loc 36
rs 9.536
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A UnknownRoleDescriptor::__construct() 0 29 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\AbstractElement;
10
use SimpleSAML\XML\Chunk;
11
use SimpleSAML\XML\Exception\InvalidDOMElementException;
12
use SimpleSAML\XML\Exception\TooManyElementsException;
13
use SimpleSAML\XML\Utils as XMLUtils;
14
15
use function preg_split;
16
17
/**
18
 * Class representing unknown RoleDescriptors.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class UnknownRoleDescriptor extends AbstractRoleDescriptor
23
{
24
    /** @var \SimpleSAML\XML\Chunk */
25
    protected Chunk $chunk;
26
27
    /**
28
     * Initialize a saml:RoleDescriptor from scratch.
29
     *
30
     * @param \SimpleSAML\XML\Chunk $chunk The whole RoleDescriptor element as a chunk object.
31
     * @param string $type
32
     * @param string[] $protocolSupportEnumeration A set of URI specifying the protocols supported.
33
     * @param string|null $ID The ID for this document. Defaults to null.
34
     * @param int|null $validUntil Unix time of validity for this document. Defaults to null.
35
     * @param string|null $cacheDuration Maximum time this document can be cached. Defaults to null.
36
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An Extensions object. Defaults to null.
37
     * @param string|null $errorURL An URI where to redirect users for support. Defaults to null.
38
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptors An array of KeyDescriptor elements. Defaults to an empty array.
39
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization The organization running this entity. Defaults to null.
40
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts An array of contacts for this entity. Defaults to an empty array.
41
     * @param \DOMAttr[] $namespacedAttributes
42
     */
43
    protected function __construct(
44
        Chunk $chunk,
45
        string $type,
46
        array $protocolSupportEnumeration,
47
        ?string $ID = null,
48
        ?int $validUntil = null,
49
        ?string $cacheDuration = null,
50
        ?Extensions $extensions = null,
51
        ?string $errorURL = null,
52
        array $keyDescriptors = [],
53
        ?Organization $organization = null,
54
        array $contacts = [],
55
        array $namespacedAttributes = []
56
    ) {
57
        parent::__construct(
58
            $type,
59
            $protocolSupportEnumeration,
60
            $ID,
61
            $validUntil,
62
            $cacheDuration,
63
            $extensions,
64
            $errorURL,
65
            $keyDescriptors,
66
            $organization,
67
            $contacts,
68
            $namespacedAttributes
69
        );
70
71
        $this->chunk = $chunk;
72
    }
73
74
75
    /**
76
     * Get the raw version of this RoleDescriptor as a Chunk.
77
     *
78
     * @return \SimpleSAML\XML\Chunk
79
     */
80
    public function getRawRoleDescriptor(): Chunk
81
    {
82
        return $this->chunk;
83
    }
84
85
86
    /**
87
     * Convert this RoleDescriptor to XML.
88
     *
89
     * @param \DOMElement|null $parent The element we are converting to XML.
90
     * @return \DOMElement The XML element after adding the data corresponding to this unknown RoleDescriptor.
91
     */
92
    public function toXML(DOMElement $parent = null): DOMElement
93
    {
94
        return $this->getRawRoleDescriptor()->toXML($parent);
95
    }
96
}
97