Completed
Push — master ( 4e360d...80bc96 )
by Daan van
07:27
created

ArtifactResponse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 8
c 3
b 1
f 0
lcom 1
cbo 2
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 4
A setAny() 0 4 1
A getAny() 0 4 1
A toUnsignedXML() 0 10 2
1
<?php
2
3
namespace SAML2;
4
5
/**
6
 * The \SAML2\ArtifactResponse, is the response to the \SAML2\ArtifactResolve.
7
 *
8
 * @author Danny Bollaert, UGent AS. <[email protected]>
9
 * @package SimpleSAMLphp
10
 */
11
class ArtifactResponse extends StatusResponse
12
{
13
    /**
14
     * The \DOMElement with the message the artifact refers
15
     * to, or null if we don't refer to any artifact.
16
     *
17
     * @var \DOMElement|null
18
     */
19
    private $any;
20
21
22
    public function __construct(\DOMElement $xml = null)
23
    {
24
        parent::__construct('ArtifactResponse', $xml);
25
26
        if (!is_null($xml)) {
27
            $status = Utils::xpQuery($xml, './saml_protocol:Status');
28
            assert('!empty($status)'); /* Will have failed during StatusResponse parsing. */
29
30
            $status = $status[0];
31
32
            for ($any = $status->nextSibling; $any !== null; $any = $any->nextSibling) {
33
                if ($any instanceof \DOMElement) {
34
                    $this->any = $any;
35
                    break;
36
                }
37
                /* Ignore comments and text nodes. */
38
            }
39
        }
40
    }
41
42
    public function setAny(\DOMElement $any = null)
43
    {
44
        $this->any = $any;
45
    }
46
47
    public function getAny()
48
    {
49
        return $this->any;
50
    }
51
52
    /**
53
     * Convert the response message to an XML element.
54
     *
55
     * @return \DOMElement This response.
56
     */
57
    public function toUnsignedXML()
58
    {
59
        $root = parent::toUnsignedXML();
60
        if (isset($this->any)) {
61
            $node = $root->ownerDocument->importNode($this->any, true);
62
            $root->appendChild($node);
63
        }
64
65
        return $root;
66
    }
67
}
68