Passed
Push — master ( eb6d7f...017f7a )
by Tim
02:40
created

AbstractSignedMdElement   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 19 4
A getBlacklistedAlgorithms() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\XMLSecurity\XML\SignableElementTrait;
9
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
10
use SimpleSAML\XMLSecurity\XML\SignedElementTrait;
11
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;
12
13
/**
14
 * Abstract class that represents a signed metadata element.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
abstract class AbstractSignedMdElement extends AbstractMdElement implements SignableElementInterface, SignedElementInterface
19
{
20
    use SignableElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XMLSecurity\XML\SignableElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\md\AbstractSignedMdElement: $ownerDocument, $documentElement
Loading history...
21
    use SignedElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XMLSecurity\XML\SignedElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\md\AbstractSignedMdElement: $ownerDocument, $documentElement
Loading history...
22
23
24
    /**
25
     * @return array|null
26
     */
27
    public function getBlacklistedAlgorithms(): ?array
28
    {
29
        $container = ContainerSingleton::getInstance();
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\md\ContainerSingleton 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...
30
        return $container->getBlacklistedEncryptionAlgorithms();
31
    }
32
33
34
    /**
35
     * @param \DOMElement|null $parent The EntityDescriptor we should append this SPSSODescriptor to.
36
     * @return \DOMElement
37
     * @throws \Exception
38
     */
39
    public function toXML(DOMElement $parent = null): DOMElement
40
    {
41
        if ($this->isSigned() === true && $this->signer === null) {
42
            $e = $this->instantiateParentElement($parent);
43
44
            // We already have a signed document and no signer was set to re-sign it
45
            $node = $e->ownerDocument->importNode($this->xml, true);
0 ignored issues
show
Bug introduced by
The method importNode() 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

45
            /** @scrutinizer ignore-call */ 
46
            $node = $e->ownerDocument->importNode($this->xml, true);

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...
46
            return $e->appendChild($node);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $e->appendChild($node) returns the type DOMNode which includes types incompatible with the type-hinted return DOMElement.
Loading history...
47
        }
48
49
        $e = $this->toUnsignedXML($parent);
0 ignored issues
show
Bug introduced by
The method toUnsignedXML() does not exist on SimpleSAML\SAML2\XML\md\AbstractSignedMdElement. Since it exists in all sub-types, consider adding an abstract or default implementation to SimpleSAML\SAML2\XML\md\AbstractSignedMdElement. ( Ignorable by Annotation )

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

49
        /** @scrutinizer ignore-call */ 
50
        $e = $this->toUnsignedXML($parent);
Loading history...
50
51
        if ($this->signer !== null) {
52
            $signedXML = $this->doSign($e);
53
            $signedXML->insertBefore($this->signature->toXML($signedXML), $signedXML->firstChild);
54
            return $signedXML;
55
        }
56
57
        return $e;
58
    }
59
}
60