KeyInfoReference::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6
7
use DOMElement;
8
use SimpleSAML\XML\SchemaValidatableElementInterface;
9
use SimpleSAML\XML\SchemaValidatableElementTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Type\AnyURIValue;
12
use SimpleSAML\XMLSchema\Type\IDValue;
13
use SimpleSAML\XMLSecurity\Assert\Assert;
14
15
/**
16
 * Class representing a dsig11:KeyInfoReference element.
17
 *
18
 * @package simplesamlphp/xml-security
19
 */
20
final class KeyInfoReference extends AbstractDsig11Element implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\X...1\AbstractDsig11Element 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
{
22
    use SchemaValidatableElementTrait;
23
24
25
    /**
26
     * Initialize a KeyInfoReference element.
27
     *
28
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $URI
29
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
30
     */
31
    public function __construct(
32
        protected AnyURIValue $URI,
33
        protected ?IDValue $Id = null,
34
    ) {
35
    }
36
37
38
    /**
39
     * Collect the value of the URI-property
40
     *
41
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
42
     */
43
    public function getURI(): AnyURIValue
44
    {
45
        return $this->URI;
46
    }
47
48
49
    /**
50
     * Collect the value of the Id-property
51
     *
52
     * @return \SimpleSAML\XMLSchema\Type\IDValue|null
53
     */
54
    public function getId(): ?IDValue
55
    {
56
        return $this->Id;
57
    }
58
59
60
    /**
61
     * Convert XML into a KeyInfoReference
62
     *
63
     * @param \DOMElement $xml The XML element we should load
64
     *
65
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
66
     *   If the qualified name of the supplied element is wrong
67
     */
68
    public static function fromXML(DOMElement $xml): static
69
    {
70
        Assert::same($xml->localName, 'KeyInfoReference', InvalidDOMElementException::class);
71
        Assert::same($xml->namespaceURI, KeyInfoReference::NS, InvalidDOMElementException::class);
72
73
        return new static(
74
            KeyInfoReference::getAttribute($xml, 'URI', AnyURIValue::class),
75
            KeyInfoReference::getOptionalAttribute($xml, 'Id', IDValue::class, null),
76
        );
77
    }
78
79
80
    /**
81
     * Convert this KeyInfoReference element to XML.
82
     *
83
     * @param \DOMElement|null $parent The element we should append this KeyInfoReference element to.
84
     */
85
    public function toXML(?DOMElement $parent = null): DOMElement
86
    {
87
        $e = $this->instantiateParentElement($parent);
88
        $e->setAttribute('URI', strval($this->getURI()));
89
90
        if ($this->getId() !== null) {
91
            $e->setAttribute('Id', strval($this->getId()));
92
        }
93
94
        return $e;
95
    }
96
}
97