AbstractAttributeQueryType::toXML()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML11\XML\saml\{AttributeDesignator, Subject};
10
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
11
use SimpleSAML\XMLSchema\Type\AnyURIValue;
12
13
use function strval;
14
15
/**
16
 * Abstract class to be implemented by all the attributes queries in this namespace
17
 *
18
 * @package simplesamlphp/saml11
19
 */
20
abstract class AbstractAttributeQueryType extends AbstractSubjectQueryAbstractType
21
{
22
    /**
23
     * Initialize a samlp:AttributeQuery element.
24
     *
25
     * @param \SimpleSAML\SAML11\XML\saml\Subject $subject
26
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $resource
27
     * @param array<\SimpleSAML\SAML11\XML\saml\AttributeDesignator> $attributeDesignator
28
     */
29
    public function __construct(
30
        Subject $subject,
31
        protected ?AnyURIValue $resource = null,
32
        protected array $attributeDesignator = [],
33
    ) {
34
        Assert::allIsInstanceOf($attributeDesignator, AttributeDesignator::class, SchemaViolationException::class);
35
36
        parent::__construct($subject);
37
    }
38
39
40
    /**
41
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
42
     */
43
    public function getResource(): ?AnyURIValue
44
    {
45
        return $this->resource;
46
    }
47
48
49
    /**
50
     * @return array<\SimpleSAML\SAML11\XML\saml\AttributeDesignator>
51
     */
52
    public function getAttributeDesignator(): array
53
    {
54
        return $this->attributeDesignator;
55
    }
56
57
58
    /**
59
     * Convert this AttributeQuery to XML.
60
     *
61
     * @param \DOMElement $parent The element we are converting to XML.
62
     * @return \DOMElement The XML element after adding the data corresponding to this AttributeQuery.
63
     */
64
    public function toXML(?DOMElement $parent = null): DOMElement
65
    {
66
        $e = parent::toXML($parent);
67
68
        if ($this->getResource() !== null) {
69
            $e->setAttribute('Resource', strval($this->getResource()));
70
        }
71
72
        foreach ($this->getAttributeDesignator() as $attrDesignator) {
73
            $attrDesignator->toXML($e);
74
        }
75
76
        return $e;
77
    }
78
}
79