AbstractResponseType   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 15
c 1
b 0
f 0
dl 0
loc 101
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecipient() 0 3 1
A getInResponseTo() 0 3 1
A getStatus() 0 3 1
A toUnsignedXML() 0 19 4
A getAssertion() 0 3 1
A __construct() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML11\Assert\Assert;
9
use SimpleSAML\SAML11\Type\{SAMLAnyURIValue, SAMLDateTimeValue};
10
use SimpleSAML\SAML11\XML\saml\Assertion;
11
use SimpleSAML\SAML11\XML\samlp\Status;
12
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
13
use SimpleSAML\XMLSchema\Type\{IDValue, NCNameValue, NonNegativeIntegerValue};
14
15
use function strval;
16
17
/**
18
 * Base class for all SAML 1.1 samlp:AbstractResponseAbstractType.
19
 *
20
 * @package simplesamlphp/saml11
21
 */
22
abstract class AbstractResponseType extends AbstractResponseAbstractType
23
{
24
    /**
25
     * Initialize a response.
26
     *
27
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $majorVersion
28
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $minorVersion
29
     * @param \SimpleSAML\XMLSchema\Type\IDValue $id
30
     * @param \SimpleSAML\SAML11\XML\samlp\Status $status
31
     * @param array<\SimpleSAML\SAML11\XML\saml\Assertion> $assertion
32
     * @param \SimpleSAML\SAML11\Type\SAMLDateTimeValue|null $issueInstant
33
     * @param \SimpleSAML\XMLSchema\Type\NCNameValue|null $inResponseTo
34
     * @param \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null $recipient
35
     *
36
     * @throws \Exception
37
     */
38
    public function __construct(
39
        NonNegativeIntegerValue $majorVersion,
40
        NonNegativeIntegerValue $minorVersion,
41
        IDValue $id,
42
        protected Status $status,
43
        SAMLDateTimeValue $issueInstant,
44
        protected array $assertion = [],
45
        protected ?NCNameValue $inResponseTo = null,
46
        protected ?SAMLAnyURIValue $recipient = null,
47
    ) {
48
        Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class);
49
50
        parent::__construct($id, $majorVersion, $minorVersion, $issueInstant);
51
    }
52
53
54
    /**
55
     * Retrieve the inResponseTo of this message.
56
     *
57
     * @return \SimpleSAML\XMLSchema\Type\NCNameValue|null The inResponseTo of this message
58
     */
59
    public function getInResponseTo(): ?NCNameValue
60
    {
61
        return $this->inResponseTo;
62
    }
63
64
65
    /**
66
     * Retrieve the recipient of this message.
67
     *
68
     * @return \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null The recipient of this message
69
     */
70
    public function getRecipient(): ?SAMLAnyURIValue
71
    {
72
        return $this->recipient;
73
    }
74
75
76
    /**
77
     * Retrieve the assertion of this message.
78
     *
79
     * @return array<\SimpleSAML\SAML11\XML\saml\Assertion> The assertion of this message
80
     */
81
    public function getAssertion(): array
82
    {
83
        return $this->assertion;
84
    }
85
86
87
    /**
88
     * Retrieve the status of this message.
89
     *
90
     * @return \SimpleSAML\SAML11\XML\samlp\Status The status of this message
91
     */
92
    public function getStatus(): Status
93
    {
94
        return $this->status;
95
    }
96
97
98
    /**
99
     * Convert this message to an unsigned XML document.
100
     * This method does not sign the resulting XML document.
101
     *
102
     * @return \DOMElement The root element of the DOM tree
103
     */
104
    protected function toUnsignedXML(?DOMElement $parent = null): DOMElement
105
    {
106
        $e = parent::toUnsignedXML($parent);
107
108
        if ($this->getRecipient() !== null) {
109
            $e->setAttribute('Recipient', strval($this->getRecipient()));
110
        }
111
112
        if ($this->getInResponseTo() !== null) {
113
            $e->setAttribute('InResponseTo', strval($this->getInResponseTo()));
114
        }
115
116
        $this->getStatus()->toXML($e);
117
118
        foreach ($this->getAssertion() as $assertion) {
119
            $assertion->toXML($e);
120
        }
121
122
        return $e;
123
    }
124
}
125