AbstractEncryptionPropertyType   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 105
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 23 6
A __construct() 0 12 1
A fromXML() 0 10 1
A getTarget() 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\Constants as C;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
use SimpleSAML\XML\ExtendableAttributesTrait;
13
use SimpleSAML\XML\ExtendableElementTrait;
14
use SimpleSAML\XML\SchemaValidatableElementInterface;
15
use SimpleSAML\XML\SchemaValidatableElementTrait;
16
use SimpleSAML\XML\XsNamespace as NS;
17
use SimpleSAML\XMLSecurity\Assert\Assert;
18
19
/**
20
 * Class representing <xenc:EncryptionPropertyType>.
21
 *
22
 * @package simplesamlphp/xml-security
23
 */
24
abstract class AbstractEncryptionPropertyType extends AbstractXencElement implements
25
    SchemaValidatableElementInterface
26
{
27
    use ExtendableAttributesTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableAttributesTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\X...tEncryptionPropertyType: $localName, $nodeValue, $namespaceURI, $prefix, $attributes
Loading history...
28
    use ExtendableElementTrait;
29
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\X...tEncryptionPropertyType: $message, $line
Loading history...
30
31
    /** The namespace-attribute for the xs:anyAttribute element */
32
    public const XS_ANY_ATTR_NAMESPACE = [C::NS_XML];
33
34
    /** The namespace-attribute for the xs:any element */
35
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
36
37
38
    /**
39
     * EncryptionProperty constructor.
40
     *
41
     * @param \SimpleSAML\XML\SerializableElementInterface[] $children
42
     * @param string|null $Target
43
     * @param string|null $Id
44
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
45
     */
46
    final public function __construct(
47
        array $children,
48
        protected ?string $Target = null,
49
        protected ?string $Id = null,
50
        array $namespacedAttributes = [],
51
    ) {
52
        Assert::minCount($children, 1, MissingElementException::class);
53
        Assert::nullOrValidURI($Target, SchemaViolationException::class);
54
        Assert::nullOrValidNCName($Id, SchemaViolationException::class);
55
56
        $this->setElements($children);
57
        $this->setAttributesNS($namespacedAttributes);
58
    }
59
60
61
    /**
62
     * Get the value of the $Target property.
63
     *
64
     * @return string|null
65
     */
66
    public function getTarget(): ?string
67
    {
68
        return $this->Target;
69
    }
70
71
72
    /**
73
     * Get the value of the $Id property.
74
     *
75
     * @return string|null
76
     */
77
    public function getId(): ?string
78
    {
79
        return $this->Id;
80
    }
81
82
83
    /**
84
     * @inheritDoc
85
     *
86
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
87
     *   If the qualified name of the supplied element is wrong
88
     */
89
    public static function fromXML(DOMElement $xml): static
90
    {
91
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
92
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
93
94
        return new static(
95
            self::getChildElementsFromXML($xml),
96
            self::getOptionalAttribute($xml, 'Target', null),
97
            self::getOptionalAttribute($xml, 'Id', null),
98
            self::getAttributesNSFromXML($xml),
99
        );
100
    }
101
102
103
    /**
104
     * @inheritDoc
105
     */
106
    public function toXML(?DOMElement $parent = null): DOMElement
107
    {
108
        $e = $this->instantiateParentElement($parent);
109
110
        if ($this->getTarget() !== null) {
111
            $e->setAttribute('Target', $this->getTarget());
112
        }
113
114
        if ($this->getId() !== null) {
115
            $e->setAttribute('Id', $this->getId());
116
        }
117
118
        foreach ($this->getAttributesNS() as $attr) {
119
            $attr->toXML($e);
120
        }
121
122
        foreach ($this->getElements() as $child) {
123
            if (!$child->isEmptyElement()) {
124
                $child->toXML($e);
125
            }
126
        }
127
128
        return $e;
129
    }
130
}
131