AbstractAuthorizationDecisionQueryType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 68
rs 10

5 Methods

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