AbstractValueInRangeType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValueUpperBound() 0 3 1
A toXML() 0 8 1
A getValueLowerBound() 0 3 1
A fromXML() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\auth;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
10
11
use function array_pop;
12
13
/**
14
 * Class defining the ValueInRangeType element
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
abstract class AbstractValueInRangeType extends AbstractAuthElement
19
{
20
    /**
21
     * AbstractValueInRangeType constructor
22
     *
23
     * @param \SimpleSAML\WSSecurity\XML\auth\ValueUpperBound $valueUpperBound
24
     * @param \SimpleSAML\WSSecurity\XML\auth\ValueLowerBound $valueLowerBound
25
     */
26
    final public function __construct(
27
        protected ValueUpperBound $valueUpperBound,
28
        protected ValueLowerBound $valueLowerBound,
29
    ) {
30
    }
31
32
33
    /**
34
     * Create an instance of this object from its XML representation.
35
     *
36
     * @param \DOMElement $xml
37
     * @return static
38
     *
39
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
40
     *   if the qualified name of the supplied element is wrong
41
     */
42
    public static function fromXML(DOMElement $xml): static
43
    {
44
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
45
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
46
47
        $valueUpperBound = ValueUpperBound::getChildrenOfClass($xml);
48
        $valueLowerBound = ValueLowerBound::getChildrenOfClass($xml);
49
50
        return new static(
51
            array_pop($valueUpperBound),
52
            array_pop($valueLowerBound),
53
        );
54
    }
55
56
57
    /**
58
     * Get the value of the $valueUpperBound property.
59
     *
60
     * @return \SimpleSAML\WSSecurity\XML\auth\ValueUpperBound
61
     */
62
    public function getValueUpperBound(): ValueUpperBound
63
    {
64
        return $this->valueUpperBound;
65
    }
66
67
68
    /**
69
     * Get the value of the $valueLowerBound property.
70
     *
71
     * @return \SimpleSAML\WSSecurity\XML\auth\ValueLowerBound
72
     */
73
    public function getValueLowerBound(): ValueLowerBound
74
    {
75
        return $this->valueLowerBound;
76
    }
77
78
79
    /**
80
     * Add this ValueInRangeType to an XML element.
81
     *
82
     * @param \DOMElement|null $parent The element we should append this username token to.
83
     * @return \DOMElement
84
     */
85
    public function toXML(?DOMElement $parent = null): DOMElement
86
    {
87
        $e = parent::instantiateParentElement($parent);
88
89
        $this->getValueUpperBound()->toXML($e);
90
        $this->getValueLowerBound()->toXML($e);
91
92
        return $e;
93
    }
94
}
95