Passed
Pull Request — master (#2)
by Tim
01:58
created

AbstractSignedXMLElement::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML;
6
7
use DOMElement;
8
use SimpleSAML\XMLSecurity\XML\ds\Signature;
9
10
/**
11
 * Abstract class to be implemented by all signed classes
12
 *
13
 * @package simplesamlphp/xml-security
14
 */
15
abstract class AbstractSignedXMLElement implements SignedElementInterface
16
{
17
    use SignedElementTrait;
18
19
    /**
20
     * The signed DOM structure.
21
     *
22
     * @var \DOMElement
23
     */
24
    protected DOMElement $structure;
25
26
    /**
27
     * The unsigned elelement.
28
     *
29
     * @var \SimpleSAML\XMLSecurity\XML\SignableElementInterface
30
     */
31
    protected SignableElementInterface $element;
32
33
34
    /**
35
     * Create/parse an alg:SigningMethod element.
36
     *
37
     * @param \DOMElement $xml
38
     * @param \SimpleSAML\XMLSecurity\XML\ds\Signature $signature
39
     */
40
    protected function __construct(DOMElement $xml, Signature $signature)
41
    {
42
//        $this->element = $elt;
43
        $this->setStructure($xml);
44
        $this->setSignature($signature);
45
    }
46
47
48
    /**
49
     * Output the class as an XML-formatted string
50
     *
51
     * @return string
52
     */
53
    public function __toString(): string
54
    {
55
        return $this->structure->ownerDocument->saveXML();
0 ignored issues
show
Bug introduced by
The method saveXML() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        return $this->structure->ownerDocument->/** @scrutinizer ignore-call */ saveXML();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
    }
57
58
59
    /**
60
     * Collect the value of the structure-property
61
     *
62
     * @return \DOMElement
63
     */
64
    public function getStructure(): DOMElement
65
    {
66
        return $this->structure;
67
    }
68
69
70
    /**
71
     * Set the value of the structure-property
72
     *
73
     * @param \DOMElement $structure
74
     */
75
    private function setStructure(DOMElement $structure): void
76
    {
77
        $this->structure = $structure;
78
    }
79
80
81
    /**
82
     * Create XML from this class
83
     *
84
     * @param \DOMElement|null $parent
85
     * @return \DOMElement
86
     */
87
    public function toXML(DOMElement $parent = null): DOMElement
0 ignored issues
show
Unused Code introduced by
The parameter $parent is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function toXML(/** @scrutinizer ignore-unused */ DOMElement $parent = null): DOMElement

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
    {
89
        return $this->structure;
90
    }
91
92
93
    /**
94
     * Create a class from XML
95
     *
96
     * @param \DOMElement $xml
97
     * @return self
98
     */
99
    abstract public static function fromXML(DOMElement $xml): object;
100
}
101