Passed
Pull Request — master (#2)
by Jaime Pérez
03:26
created

CanonicalizableElementTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canonicalize() 0 3 1
A serialize() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML;
6
7
use DOMElement;
8
use SimpleSAML\XMLSecurity\Utils\XML;
9
10
/**
11
 * A trait implementing the CanonicalizableElementInterface.
12
 *
13
 * @package simplesamlphp/xml-security
14
 */
15
trait CanonicalizableElementTrait
16
{
17
    /**
18
     * This trait uses the php DOM extension. As such, it requires you to keep track (or produce) the DOMElement
19
     * necessary to perform the canonicalisation.
20
     *
21
     * Implement this method to return the DOMElement with the proper representation of this object. Whatever is
22
     * returned here will be used both to perform canonicalisation and to serialize the object, so that it can be
23
     * recovered later in its exact original state.
24
     *
25
     * @return \DOMElement
26
     */
27
    abstract protected function getOriginalXML(): DOMElement;
28
29
30
    /**
31
     * Get the canonical (string) representation of this object.
32
     *
33
     * Note that if this object was created using fromXML(), it might be necessary to keep the original DOM
34
     * representation of the object.
35
     *
36
     * @param string $method The canonicalization method to use.
37
     * @param string[]|null $xpaths An array of XPaths to filter the nodes by. Defaults to null (no filters).
38
     * @param string[]|null $prefixes An array of namespace prefixes to filter the nodes by. Defaults to null (no
39
     * filters).
40
     * @return string
41
     */
42
    public function canonicalize(string $method, ?array $xpaths = null, ?array $prefixes = null): string
43
    {
44
        return XML::canonicalizeData($this->getOriginalXML(), $method, $xpaths, $prefixes);
45
    }
46
47
48
    /**
49
     * Serialize this canonicalisable element.
50
     *
51
     * @return string The serialized chunk.
52
     */
53
    public function serialize(): string
54
    {
55
        $xml = $this->getOriginalXML();
56
        return $xml->ownerDocument->saveXML($xml);
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

56
        return $xml->ownerDocument->/** @scrutinizer ignore-call */ saveXML($xml);

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...
57
    }
58
}