AbstractRenewingType   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 16
dl 0
loc 85
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 8 1
A __construct() 0 4 1
A isEmptyElement() 0 4 2
A toXML() 0 13 3
A getOk() 0 3 1
A getAllow() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wst_200512;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
10
use SimpleSAML\XMLSchema\Type\BooleanValue;
11
12
/**
13
 * Class defining the RenewingType element
14
 *
15
 * @package simplesamlphp/ws-security
16
 */
17
abstract class AbstractRenewingType extends AbstractWstElement
18
{
19
    /**
20
     * AbstractRenewingType constructor
21
     *
22
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue|null $allow
23
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue|null $ok
24
     */
25
    final public function __construct(
26
        protected ?BooleanValue $allow = null,
27
        protected ?BooleanValue $ok = null,
28
    ) {
29
    }
30
31
32
    /**
33
     * @return \SimpleSAML\XMLSchema\Type\BooleanValue|null
34
     */
35
    public function getAllow(): ?BooleanValue
36
    {
37
        return $this->allow;
38
    }
39
40
41
    /**
42
     * @return \SimpleSAML\XMLSchema\Type\BooleanValue|null
43
     */
44
    public function getOk(): ?BooleanValue
45
    {
46
        return $this->ok;
47
    }
48
49
50
    /**
51
     * Test if an object, at the state it's in, would produce an empty XML-element
52
     *
53
     * @return bool
54
     */
55
    public function isEmptyElement(): bool
56
    {
57
        return empty($this->getAllow())
58
            && empty($this->getOk());
59
    }
60
61
62
    /**
63
     * Create an instance of this object from its XML representation.
64
     *
65
     * @param \DOMElement $xml
66
     * @return static
67
     *
68
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
69
     *   if the qualified name of the supplied element is wrong
70
     */
71
    public static function fromXML(DOMElement $xml): static
72
    {
73
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
74
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
75
76
        return new static(
77
            self::getOptionalAttribute($xml, 'Allow', BooleanValue::class, null),
78
            self::getOptionalAttribute($xml, 'OK', BooleanValue::class, null),
79
        );
80
    }
81
82
83
    /**
84
     * Add this UseKeyType to an XML element.
85
     *
86
     * @param \DOMElement|null $parent The element we should append this username token to.
87
     * @return \DOMElement
88
     */
89
    public function toXML(?DOMElement $parent = null): DOMElement
90
    {
91
        $e = parent::instantiateParentElement($parent);
92
93
        if ($this->getAllow() !== null) {
94
            $e->setAttribute('Allow', $this->getAllow()->getValue());
95
        }
96
97
        if ($this->getOk() !== null) {
98
            $e->setAttribute('OK', $this->getOk()->getValue());
99
        }
100
101
        return $e;
102
    }
103
}
104