AbstractSignedMdElement::setXML()   A
last analyzed

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 1
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\md;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\XML\SignableElementTrait;
9
use SimpleSAML\SAML2\XML\SignedElementTrait;
10
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
11
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;
12
13
use function method_exists;
14
15
/**
16
 * Abstract class that represents a signed metadata element.
17
 *
18
 * @package simplesamlphp/saml2
19
 */
20
abstract class AbstractSignedMdElement extends AbstractMdElement implements
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\AbstractMdElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
    SignableElementInterface,
22
    SignedElementInterface
23
{
24
    use SignableElementTrait;
25
    use SignedElementTrait {
26
        SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
27
    }
28
29
30
    /**
31
     * The original signed XML
32
     */
33
    protected DOMElement $xml;
34
35
36
    /**
37
     * Get the XML element.
38
     */
39
    public function getXML(): DOMElement
40
    {
41
        return $this->xml;
42
    }
43
44
45
    /**
46
     * Set the XML element.
47
     */
48
    protected function setXML(DOMElement $xml): void
49
    {
50
        $this->xml = $xml;
51
    }
52
53
54
    /**
55
     * @throws \Exception
56
     */
57
    public function toXML(?DOMElement $parent = null): DOMElement
58
    {
59
        if ($this->isSigned() === true && $this->signer === null) {
60
            // We already have a signed document and no signer was set to re-sign it
61
            if ($parent === null) {
62
                return $this->getXML();
63
            }
64
65
            $node = $parent->ownerDocument?->importNode($this->getXML(), true);
66
            $parent->appendChild($node);
67
            return $parent;
68
        }
69
70
        $e = $this->toUnsignedXML($parent);
71
72
        // This is a dirty hack, but if we add the xsi-type on AbstractRoleDescriptor we cannot
73
        // get the tests to pass because the attribute-order is messed up. This has something
74
        // to do with the fact that toUnsignedXML's recursive nature.
75
        if (method_exists(static::class, 'getXsiTypePrefix')) {
76
            $e->setAttributeNS(
77
                'http://www.w3.org/2000/xmlns/',
78
                'xmlns:' . static::getXsiTypePrefix(),
79
                static::getXsiTypeNamespaceURI()->getValue(),
80
            );
81
        }
82
83
        if ($this->signer !== null) {
84
            $signedXML = $this->doSign($e);
85
            $signedXML->insertBefore($this->signature?->toXML($signedXML), $signedXML->firstChild);
86
            return $signedXML;
87
        }
88
89
        return $e;
90
    }
91
92
93
    /**
94
     */
95
    abstract public function toUnsignedXML(?DOMElement $parent = null): DOMElement;
96
}
97