DEREncodedKeyValue::toXML()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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