AbstractEncryptionPropertiesType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\XML\SchemaValidatableElementInterface;
9
use SimpleSAML\XML\SchemaValidatableElementTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Exception\MissingElementException;
12
use SimpleSAML\XMLSchema\Type\IDValue;
13
use SimpleSAML\XMLSecurity\Assert\Assert;
14
15
use function strval;
16
17
/**
18
 * Class representing <xenc:EncryptionPropertiesType>.
19
 *
20
 * @package simplesamlphp/xml-security
21
 */
22
abstract class AbstractEncryptionPropertiesType extends AbstractXencElement implements
23
    SchemaValidatableElementInterface
24
{
25
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\X...ncryptionPropertiesType: $message, $line
Loading history...
26
27
28
    /**
29
     * EncryptionProperty constructor.
30
     *
31
     * @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty[] $encryptionProperty
32
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
33
     */
34
    final public function __construct(
35
        protected array $encryptionProperty,
36
        protected ?IDValue $Id = null,
37
    ) {
38
        Assert::minCount($encryptionProperty, 1, MissingElementException::class);
39
    }
40
41
42
    /**
43
     * Get the value of the $encryptionProperty property.
44
     *
45
     * @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty[]
46
     */
47
    public function getEncryptionProperty(): array
48
    {
49
        return $this->encryptionProperty;
50
    }
51
52
53
    /**
54
     * Get 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
     * @inheritDoc
66
     *
67
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
68
     *   If the qualified name of the supplied element is wrong
69
     */
70
    public static function fromXML(DOMElement $xml): static
71
    {
72
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
73
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
74
75
        return new static(
76
            EncryptionProperty::getChildrenOfClass($xml),
77
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
78
        );
79
    }
80
81
82
    /**
83
     * @inheritDoc
84
     */
85
    public function toXML(?DOMElement $parent = null): DOMElement
86
    {
87
        $e = $this->instantiateParentElement($parent);
88
89
        foreach ($this->getEncryptionProperty() as $ep) {
90
            $ep->toXML($e);
91
        }
92
93
        if ($this->getId() !== null) {
94
            $e->setAttribute('Id', strval($this->getId()));
95
        }
96
97
        return $e;
98
    }
99
}
100