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

UnknownRoleDescriptor::fromXML()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 42
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 28
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 42
rs 9.1608

2 Methods

Rating   Name   Duplication   Size   Complexity  
A UnknownRoleDescriptor::__construct() 0 26 1
A UnknownRoleDescriptor::getRawRoleDescriptor() 0 3 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\SAML2\Utils\XPath;
10
use SimpleSAML\XML\AbstractElement;
11
use SimpleSAML\XML\Chunk;
12
use SimpleSAML\XML\Exception\InvalidDOMElementException;
13
use SimpleSAML\XML\Exception\TooManyElementsException;
14
use SimpleSAML\XML\Utils as XMLUtils;
15
use SimpleSAML\XMLSecurity\XML\ds\Signature;
16
17
use function array_pop;
18
use function preg_split;
19
20
/**
21
 * Class representing unknown RoleDescriptors.
22
 *
23
 * @package simplesamlphp/saml2
24
 */
25
final class UnknownRoleDescriptor extends AbstractRoleDescriptor
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
        protected 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
72
73
    /**
74
     * Get the raw version of this RoleDescriptor as a Chunk.
75
     *
76
     * @return \SimpleSAML\XML\Chunk
77
     */
78
    public function getRawRoleDescriptor(): Chunk
79
    {
80
        return $this->chunk;
81
    }
82
83
84
    /**
85
     * Convert this RoleDescriptor to XML.
86
     *
87
     * @param \DOMElement|null $parent The element we are converting to XML.
88
     * @return \DOMElement The XML element after adding the data corresponding to this unknown RoleDescriptor.
89
     */
90
    public function toXML(DOMElement $parent = null): DOMElement
91
    {
92
        return $this->getRawRoleDescriptor()->toXML($parent);
93
    }
94
}
95