AbstractEncryptionPropertiesType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 75
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromXML() 0 8 1
A toXML() 0 13 3
A getEncryptionProperty() 0 3 1
A getId() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
9
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingElementException, SchemaViolationException};
10
use SimpleSAML\XMLSchema\Type\IDValue;
11
use SimpleSAML\XMLSecurity\Assert\Assert;
12
13
use function strval;
14
15
/**
16
 * Class representing <xenc:EncryptionPropertiesType>.
17
 *
18
 * @package simplesamlphp/xml-security
19
 */
20
abstract class AbstractEncryptionPropertiesType extends AbstractXencElement implements
21
    SchemaValidatableElementInterface
22
{
23
    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...
24
25
    /**
26
     * EncryptionProperty constructor.
27
     *
28
     * @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty[] $encryptionProperty
29
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
30
     */
31
    final public function __construct(
32
        protected array $encryptionProperty,
33
        protected ?IDValue $Id = null,
34
    ) {
35
        Assert::minCount($encryptionProperty, 1, MissingElementException::class);
36
    }
37
38
39
    /**
40
     * Get the value of the $encryptionProperty property.
41
     *
42
     * @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty[]
43
     */
44
    public function getEncryptionProperty(): array
45
    {
46
        return $this->encryptionProperty;
47
    }
48
49
50
    /**
51
     * Get the value of the $Id property.
52
     *
53
     * @return \SimpleSAML\XMLSchema\Type\IDValue|null
54
     */
55
    public function getId(): ?IDValue
56
    {
57
        return $this->Id;
58
    }
59
60
61
    /**
62
     * @inheritDoc
63
     *
64
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
65
     *   If the qualified name of the supplied element is wrong
66
     */
67
    public static function fromXML(DOMElement $xml): static
68
    {
69
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
70
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
71
72
        return new static(
73
            EncryptionProperty::getChildrenOfClass($xml),
74
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
75
        );
76
    }
77
78
79
    /**
80
     * @inheritDoc
81
     */
82
    public function toXML(?DOMElement $parent = null): DOMElement
83
    {
84
        $e = $this->instantiateParentElement($parent);
85
86
        foreach ($this->getEncryptionProperty() as $ep) {
87
            $ep->toXML($e);
88
        }
89
90
        if ($this->getId() !== null) {
91
            $e->setAttribute('Id', strval($this->getId()));
92
        }
93
94
        return $e;
95
    }
96
}
97