AbstractAttributeQueryType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 2
b 0
f 0
dl 0
loc 57
rs 10

4 Methods

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