AbstractRoleDescriptorType   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
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
A __construct() 0 28 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\AnyURIListValue;
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
use function strval;
19
20
/**
21
 * Class representing SAML2 RoleDescriptorType.
22
 *
23
 * @package simplesamlphp/saml2
24
 */
25
abstract class AbstractRoleDescriptorType extends AbstractMetadataDocument
26
{
27
    use ExtendableAttributesTrait;
28
29
30
    /** The namespace-attribute for the xs:anyAttribute element */
31
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
32
33
34
    /**
35
     * Initialize a RoleDescriptor.
36
     *
37
     * @param \SimpleSAML\SAML2\Type\AnyURIListValue $protocolSupportEnumeration
38
     *   A set of URI specifying the protocols supported.
39
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $ID The ID for this document. Defaults to null.
40
     * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null $validUntil Unix time of validity for this document.
41
     *   Defaults to null.
42
     * @param \SimpleSAML\XMLSchema\Type\DurationValue|null $cacheDuration Maximum time this document can be cached.
43
     *   Defaults to null.
44
     * @param \SimpleSAML\SAML2\XML\md\Extensions|null $extensions An Extensions object. Defaults to null.
45
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $errorURL An URI where to redirect users for support.
46
     *   Defaults to null.
47
     * @param \SimpleSAML\SAML2\XML\md\KeyDescriptor[] $keyDescriptor An array of KeyDescriptor elements.
48
     *   Defaults to an empty array.
49
     * @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
50
     *   The organization running this entity. Defaults to null.
51
     * @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contact
52
     *   An array of contacts for this entity. Defaults to an empty array.
53
     * @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...
54
     */
55
    public function __construct(
56
        protected AnyURIListValue $protocolSupportEnumeration,
57
        ?IDValue $ID = null,
58
        ?SAMLDateTimeValue $validUntil = null,
59
        ?DurationValue $cacheDuration = null,
60
        ?Extensions $extensions = null,
61
        protected ?SAMLAnyURIValue $errorURL = null,
62
        protected array $keyDescriptor = [],
63
        protected ?Organization $organization = null,
64
        protected array $contact = [],
65
        array $namespacedAttributes = [],
66
    ) {
67
        Assert::maxCount($contact, C::UNBOUNDED_LIMIT);
68
        Assert::allIsInstanceOf(
69
            $contact,
70
            ContactPerson::class,
71
            'All contacts must be an instance of md:ContactPerson',
72
        );
73
        Assert::maxCount($keyDescriptor, C::UNBOUNDED_LIMIT);
74
        Assert::allIsInstanceOf(
75
            $keyDescriptor,
76
            KeyDescriptor::class,
77
            'All key descriptors must be an instance of md:KeyDescriptor',
78
        );
79
80
        parent::__construct($ID, $validUntil, $cacheDuration, $extensions);
81
82
        $this->setAttributesNS($namespacedAttributes);
83
    }
84
85
86
    /**
87
     * Collect the value of the errorURL property.
88
     *
89
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null
90
     */
91
    public function getErrorURL(): ?SAMLAnyURIValue
92
    {
93
        return $this->errorURL;
94
    }
95
96
97
    /**
98
     * Collect the value of the protocolSupportEnumeration property.
99
     *
100
     * @return \SimpleSAML\SAML2\Type\AnyURIListValue
101
     */
102
    public function getProtocolSupportEnumeration(): AnyURIListValue
103
    {
104
        return $this->protocolSupportEnumeration;
105
    }
106
107
108
    /**
109
     * Collect the value of the Organization property.
110
     *
111
     * @return \SimpleSAML\SAML2\XML\md\Organization|null
112
     */
113
    public function getOrganization(): ?Organization
114
    {
115
        return $this->organization;
116
    }
117
118
119
    /**
120
     * Collect the value of the ContactPersons property.
121
     *
122
     * @return \SimpleSAML\SAML2\XML\md\ContactPerson[]
123
     */
124
    public function getContactPerson(): array
125
    {
126
        return $this->contact;
127
    }
128
129
130
    /**
131
     * Collect the value of the KeyDescriptors property.
132
     *
133
     * @return \SimpleSAML\SAML2\XML\md\KeyDescriptor[]
134
     */
135
    public function getKeyDescriptor(): array
136
    {
137
        return $this->keyDescriptor;
138
    }
139
140
141
    /**
142
     * Add this RoleDescriptor to an EntityDescriptor.
143
     *
144
     * @param \DOMElement $parent The EntityDescriptor we should append this endpoint to.
145
     * @return \DOMElement
146
     */
147
    public function toUnsignedXML(?DOMElement $parent = null): DOMElement
148
    {
149
        $e = parent::toUnsignedXML($parent);
150
        $e->setAttribute('protocolSupportEnumeration', strval($this->getProtocolSupportEnumeration()));
151
152
        if ($this->getErrorURL() !== null) {
153
            $e->setAttribute('errorURL', strval($this->getErrorURL()));
154
        }
155
156
        foreach ($this->getKeyDescriptor() as $kd) {
157
            $kd->toXML($e);
158
        }
159
160
        $this->getOrganization()?->toXML($e);
161
162
        foreach ($this->getContactPerson() as $cp) {
163
            $cp->toXML($e);
164
        }
165
166
        foreach ($this->getAttributesNS() as $attr) {
167
            $attr->toXML($e);
168
        }
169
170
        return $e;
171
    }
172
}
173