Salt   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 6 1
A getContent() 0 3 1
A __construct() 0 3 1
A fromXML() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc11;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
10
11
use function array_merge;
12
use function array_pop;
13
14
/**
15
 * Class representing <xenc11:Salt>.
16
 *
17
 * @package simplesamlphp/xml-security
18
 */
19
final class Salt extends AbstractXenc11Element
20
{
21
    /**
22
     * Salt constructor.
23
     *
24
     * @param \SimpleSAML\XMLSecurity\XML\xenc11\OtherSource|\SimpleSAML\XMLSecurity\XML\xenc11\Specified $content
25
     */
26
    public function __construct(
27
        protected OtherSource|Specified $content,
28
    ) {
29
    }
30
31
32
    /**
33
     * Get the value of the $content property.
34
     *
35
     * @return \SimpleSAML\XMLSecurity\XML\xenc11\OtherSource|\SimpleSAML\XMLSecurity\XML\xenc11\Specified
36
     */
37
    public function getContent(): OtherSource|Specified
38
    {
39
        return $this->content;
40
    }
41
42
43
    /**
44
     * @inheritDoc
45
     *
46
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
47
     *   If the qualified name of the supplied element is wrong
48
     */
49
    public static function fromXML(DOMElement $xml): static
50
    {
51
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
52
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
53
54
        $otherSource = OtherSource::getChildrenOfClass($xml);
55
        $specified = Specified::getChildrenOfClass($xml);
56
57
        $content = array_merge($otherSource, $specified);
58
        Assert::minCount($content, 1, MissingElementException::class);
59
        Assert::maxCount($content, 1, TooManyElementsException::class);
60
61
        return new static(array_pop($content));
62
    }
63
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = $this->instantiateParentElement($parent);
71
        $this->getContent()->toXML($e);
72
73
        return $e;
74
    }
75
}
76