AbstractRoleDescriptorType   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 146
rs 10
c 0
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 28 1
A toUnsignedXML() 0 24 5
A getKeyDescriptor() 0 3 1
A getOrganization() 0 3 1
A getProtocolSupportEnumeration() 0 3 1
A getContactPerson() 0 3 1
A getErrorURL() 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\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Constants as C;
10
use SimpleSAML\SAML2\Type\SAMLAnyURIListValue;
11
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
12
use SimpleSAML\SAML2\Type\SAMLDateTimeValue;
13
use SimpleSAML\XML\ExtendableAttributesTrait;
14
use SimpleSAML\XMLSchema\Type\DurationValue;
15
use SimpleSAML\XMLSchema\Type\IDValue;
16
use SimpleSAML\XMLSchema\XML\Constants\NS;
17
18
/**
19
 * Class representing SAML2 RoleDescriptorType.
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
abstract class AbstractRoleDescriptorType extends AbstractMetadataDocument
24
{
25
    use ExtendableAttributesTrait;
26
27
28
    /** The namespace-attribute for the xs:anyAttribute element */
29
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
30
31
32
    /**
33
     * Initialize a RoleDescriptor.
34
     *
35
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIListValue $protocolSupportEnumeration
36
     *   A set of URI specifying the protocols supported.
37
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $ID The ID for this document. Defaults to null.
38
     * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null $validUntil Unix time of validity for this document.
39
     *   Defaults to null.
40
     * @param \SimpleSAML\XMLSchema\Type\DurationValue|null $cacheDuration Maximum time this document can be cached.
41
     *   Defaults to null.
42
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An Extensions object. Defaults to null.
43
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $errorURL An URI where to redirect users for support.
44
     *   Defaults to null.
45
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptor An array of KeyDescriptor elements.
46
     *   Defaults to an empty array.
47
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
48
     *   The organization running this entity. Defaults to null.
49
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contact
50
     *   An array of contacts for this entity. Defaults to an empty array.
51
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
     */
53
    public function __construct(
54
        protected SAMLAnyURIListValue $protocolSupportEnumeration,
55
        ?IDValue $ID = null,
56
        ?SAMLDateTimeValue $validUntil = null,
57
        ?DurationValue $cacheDuration = null,
58
        ?Extensions $extensions = null,
59
        protected ?SAMLAnyURIValue $errorURL = null,
60
        protected array $keyDescriptor = [],
61
        protected ?Organization $organization = null,
62
        protected array $contact = [],
63
        array $namespacedAttributes = [],
64
    ) {
65
        Assert::maxCount($contact, C::UNBOUNDED_LIMIT);
66
        Assert::allIsInstanceOf(
67
            $contact,
68
            ContactPerson::class,
69
            'All contacts must be an instance of md:ContactPerson',
70
        );
71
        Assert::maxCount($keyDescriptor, C::UNBOUNDED_LIMIT);
72
        Assert::allIsInstanceOf(
73
            $keyDescriptor,
74
            KeyDescriptor::class,
75
            'All key descriptors must be an instance of md:KeyDescriptor',
76
        );
77
78
        parent::__construct($ID, $validUntil, $cacheDuration, $extensions);
79
80
        $this->setAttributesNS($namespacedAttributes);
81
    }
82
83
84
    /**
85
     * Collect the value of the errorURL property.
86
     *
87
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null
88
     */
89
    public function getErrorURL(): ?SAMLAnyURIValue
90
    {
91
        return $this->errorURL;
92
    }
93
94
95
    /**
96
     * Collect the value of the protocolSupportEnumeration property.
97
     *
98
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIListValue
99
     */
100
    public function getProtocolSupportEnumeration(): SAMLAnyURIListValue
101
    {
102
        return $this->protocolSupportEnumeration;
103
    }
104
105
106
    /**
107
     * Collect the value of the Organization property.
108
     *
109
     * @return \SimpleSAML\SAML2\XML\md\Organization|null
110
     */
111
    public function getOrganization(): ?Organization
112
    {
113
        return $this->organization;
114
    }
115
116
117
    /**
118
     * Collect the value of the ContactPersons property.
119
     *
120
     * @return \SimpleSAML\SAML2\XML\md\ContactPerson[]
121
     */
122
    public function getContactPerson(): array
123
    {
124
        return $this->contact;
125
    }
126
127
128
    /**
129
     * Collect the value of the KeyDescriptors property.
130
     *
131
     * @return \SimpleSAML\SAML2\XML\md\KeyDescriptor[]
132
     */
133
    public function getKeyDescriptor(): array
134
    {
135
        return $this->keyDescriptor;
136
    }
137
138
139
    /**
140
     * Add this RoleDescriptor to an EntityDescriptor.
141
     *
142
     * @param \DOMElement $parent The EntityDescriptor we should append this endpoint to.
143
     * @return \DOMElement
144
     */
145
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
146
    {
147
        $e = parent::toUnsignedXML($parent);
148
        $e->setAttribute('protocolSupportEnumeration', $this->getProtocolSupportEnumeration()->getValue());
149
150
        if ($this->getErrorURL() !== null) {
151
            $e->setAttribute('errorURL', $this->getErrorURL()->getValue());
152
        }
153
154
        foreach ($this->getKeyDescriptor() as $kd) {
155
            $kd->toXML($e);
156
        }
157
158
        $this->getOrganization()?->toXML($e);
159
160
        foreach ($this->getContactPerson() as $cp) {
161
            $cp->toXML($e);
162
        }
163
164
        foreach ($this->getAttributesNS() as $attr) {
165
            $attr->toXML($e);
166
        }
167
168
        return $e;
169
    }
170
}
171