Passed
Pull Request — master (#280)
by Tim
02:30
created

AbstractSubjectQuery::getSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\XML\saml\Issuer;
9
use SimpleSAML\SAML2\XML\saml\Subject;
10
use SimpleSAML\Assert\Assert;
11
12
/**
13
 * Base class for SAML 2 subject query messages.
14
 *
15
 * This base class can be used for various requests which ask for
16
 * information about a particular subject.
17
 *
18
 * Note that this class currently only handles the simple case - where the
19
 * subject doesn't contain any sort of subject confirmation requirements.
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
abstract class AbstractSubjectQuery extends AbstractRequest
24
{
25
    /** @var \SimpleSAML\SAML2\XML\saml\Subject */
26
    protected Subject $subject;
27
28
29
    /**
30
     * Constructor for SAML 2 response messages.
31
     *
32
     * @param \SimpleSAML\SAML2\XML\saml\Subject $subject
33
     * @param \SimpleSAML\SAML2\XML\saml\Issuer $issuer
34
     * @param string $id
35
     * @param int $issueInstant
36
     * @param string|null $destination
37
     * @param string|null $consent
38
     * @param \SimpleSAML\SAML2\XML\samlp\Extensions $extensions
39
     */
40
    protected function __construct(
41
        Subject $subject,
42
        ?Issuer $issuer = null,
43
        ?string $id = null,
44
        ?int $issueInstant = null,
45
        ?string $destination = null,
46
        ?string $consent = null,
47
        ?Extensions $extensions = null
48
    ) {
49
        parent::__construct($issuer, $id, $issueInstant, $destination, $consent, $extensions);
50
51
        $this->setSubject($subject);
52
    }
53
54
55
    /**
56
     * Collect the value of the subject
57
     *
58
     * @return \SimpleSAML\SAML2\XML\saml\Subject
59
     */
60
    public function getSubject(): Subject
61
    {
62
        return $this->subject;
63
    }
64
65
66
    /**
67
     * Set the value of the subject-property
68
     * @param \SimpleSAML\SAML2\XML\saml\Subject $subject
69
     *
70
     */
71
    private function setSubject(Subject $subject): void
72
    {
73
        $this->subject = $subject;
74
    }
75
76
77
    /**
78
     * Convert this message to an unsigned XML document.
79
     * This method does not sign the resulting XML document.
80
     *
81
     * @return \DOMElement The root element of the DOM tree
82
     */
83
    protected function toUnsignedXML(?DOMElement $parent = null): DOMElement
84
    {
85
        Assert::notEmpty($this->subject, 'Cannot convert SubjectQuery to XML without a Subject set.');
86
87
        $parent = parent::toUnsignedXML($parent);
88
89
        $this->subject->toXML($parent);
90
91
        return $parent;
92
    }
93
}
94