AbstractActionType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A fromXML() 0 8 1
A toXML() 0 10 2
A getNamespace() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML11\Type\{SAMLAnyURIValue, SAMLStringValue};
10
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException};
11
12
use function strval;
13
14
/**
15
 * SAML ActionType abstract data type.
16
 *
17
 * @package simplesamlphp/saml11
18
 */
19
abstract class AbstractActionType extends AbstractSamlElement
20
{
21
    /**
22
     * Initialize a saml:AbstractActionType from scratch
23
     *
24
     * @param \SimpleSAML\SAML11\Type\SAMLStringValue $value
25
     * @param \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null $Namespace
26
     */
27
    final public function __construct(
28
        protected SAMLStringValue $value,
29
        protected ?SAMLAnyURIValue $Namespace = null,
30
    ) {
31
    }
32
33
34
    /**
35
     * Collect the value of the element
36
     *
37
     * @return \SimpleSAML\SAML11\Type\SAMLStringValue|null
38
     */
39
    public function getValue(): SAMLStringValue
40
    {
41
        return $this->value;
42
    }
43
44
45
    /**
46
     * Collect the value of the Namespace-property
47
     *
48
     * @return \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null
49
     */
50
    public function getNamespace(): ?SAMLAnyURIValue
51
    {
52
        return $this->Namespace;
53
    }
54
55
56
    /**
57
     * Convert XML into an ActionType
58
     *
59
     * @param \DOMElement $xml The XML element we should load
60
     * @return static
61
     *
62
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
63
     *   if the qualified name of the supplied element is wrong
64
     */
65
    public static function fromXML(DOMElement $xml): static
66
    {
67
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
68
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
69
70
        return new static(
71
            SAMLStringValue::fromString($xml->textContent),
72
            self::getOptionalAttribute($xml, 'Namespace', SAMLAnyURIValue::class),
73
        );
74
    }
75
76
77
    /**
78
     * Convert this ActionType to XML.
79
     *
80
     * @param \DOMElement $parent The element we are converting to XML.
81
     * @return \DOMElement The XML element after adding the data corresponding to this ActionType.
82
     */
83
    public function toXML(?DOMElement $parent = null): DOMElement
84
    {
85
        $e = $this->instantiateParentElement($parent);
86
        $e->textContent = strval($this->getValue());
87
88
        if ($this->getNamespace() !== null) {
89
            $e->setAttribute('Namespace', strval($this->getNamespace()));
90
        }
91
92
        return $e;
93
    }
94
}
95