Passed
Pull Request — master (#4)
by Tim
02:11 queued 16s
created

AbstractResponseType::getRecipient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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