SignatureProperties::getSignatureProperty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\XML\Constants as C;
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
14
use SimpleSAML\XMLSchema\Type\IDValue;
15
use SimpleSAML\XMLSecurity\Assert\Assert;
16
17
use function strval;
18
19
/**
20
 * Class representing a ds:SignatureProperties element.
21
 *
22
 * @package simplesamlphp/xml-security
23
 */
24
final class SignatureProperties extends AbstractDsElement implements SchemaValidatableElementInterface
25
{
26
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\ds\SignatureProperties: $message, $line
Loading history...
27
28
29
    /**
30
     * Initialize a ds:SignatureProperties
31
     *
32
     * @param \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[] $signatureProperty
33
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
34
     */
35
    public function __construct(
36
        protected array $signatureProperty,
37
        protected ?IDValue $Id = null,
38
    ) {
39
        Assert::maxCount($signatureProperty, C::UNBOUNDED_LIMIT);
40
        Assert::allIsInstanceOf($signatureProperty, SignatureProperty::class, SchemaViolationException::class);
41
    }
42
43
44
    /**
45
     * @return \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[]
46
     */
47
    public function getSignatureProperty(): array
48
    {
49
        return $this->signatureProperty;
50
    }
51
52
53
    /**
54
     * @return \SimpleSAML\XMLSchema\Type\IDValue|null
55
     */
56
    public function getId(): ?IDValue
57
    {
58
        return $this->Id;
59
    }
60
61
62
    /**
63
     * Convert XML into a SignatureProperties element
64
     *
65
     * @param \DOMElement $xml The XML element we should load
66
     * @return static
67
     *
68
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
69
     *   If the qualified name of the supplied element is wrong
70
     */
71
    public static function fromXML(DOMElement $xml): static
72
    {
73
        Assert::same($xml->localName, 'SignatureProperties', InvalidDOMElementException::class);
74
        Assert::same($xml->namespaceURI, SignatureProperties::NS, InvalidDOMElementException::class);
75
76
        $signatureProperty = SignatureProperty::getChildrenOfClass($xml);
77
        Assert::minCount(
78
            $signatureProperty,
79
            1,
80
            'A <ds:SignatureProperties> must contain at least one <ds:SignatureProperty>.',
81
            MissingElementException::class,
82
        );
83
84
        return new static(
85
            $signatureProperty,
86
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
87
        );
88
    }
89
90
91
    /**
92
     * Convert this SignatureProperties element to XML.
93
     *
94
     * @param \DOMElement|null $parent The element we should append this SignatureProperties element to.
95
     * @return \DOMElement
96
     */
97
    public function toXML(?DOMElement $parent = null): DOMElement
98
    {
99
        $e = $this->instantiateParentElement($parent);
100
101
        if ($this->getId() !== null) {
102
            $e->setAttribute('Id', strval($this->getId()));
103
        }
104
105
        foreach ($this->getSignatureProperty() as $signatureProperty) {
106
            $signatureProperty->toXML($e);
107
        }
108
109
        return $e;
110
    }
111
}
112