EidasRequestedAttribute   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 29
dl 0
loc 42
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 5
A toXML() 0 14 2
1
<?php
2
3
namespace OMSAML2\Chunks;
4
5
use DOMElement;
6
use SAML2\XML\Chunk;
7
8
class EidasRequestedAttribute extends Chunk
9
{
10
11
    const NAME_FORMAT_URI = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri';
12
    const NS_EIDAS = 'http://eidas.europa.eu/saml-extensions';
13
    const LOCAL_NAME = 'RequestedAttribute';
14
    const QUALIFIED_NAME = 'eidas:' . self::LOCAL_NAME;
15
16
    public $Name = null;
17
    public $isRequired = false;
18
    public $NameFormat = self::NAME_FORMAT_URI;
19
    public $NodeValue = null;
20
21
    public function __construct(?DOMElement $xml = null)
22
    {
23
        if (empty($xml)) {
24
            return;
25
        }
26
        parent::__construct($xml);
27
        $this->Name = $xml->attributes->getNamedItem('Name')->nodeValue;
28
        $isRequired = $xml->attributes->getNamedItem('isRequired');
29
        $this->isRequired = empty($isRequired) ? false : $isRequired->nodeValue;
30
        $NameFormat = $xml->attributes->getNamedItem('NameFormat');
31
        $this->NameFormat = empty($NameFormat) ? self::NAME_FORMAT_URI : $NameFormat->nodeValue;
32
        $NodeValue = $xml->getElementsByTagNameNS(self::NS_EIDAS, 'AttributeValue')->item(0);
33
        $this->NodeValue = empty($NodeValue) ? null : $NodeValue->nodeValue;
34
    }
35
36
    public function toXML(DOMElement $parent): DOMElement
37
    {
38
        $e = $parent->ownerDocument->createElementNS(self::NS_EIDAS, self::QUALIFIED_NAME);
39
        $e->setAttribute('Name', $this->Name);
40
        $e->setAttribute('NameFormat', $this->NameFormat);
41
        $e->setAttribute('isRequired', $this->isRequired);
42
        if ($this->NodeValue != null) {
43
            $val = $e->ownerDocument->createElementNS(self::NS_EIDAS, 'eidas:AttributeValue');
44
            // to support boolean values as well
45
            $val->nodeValue = var_export($this->NodeValue, true);
46
            $e->appendChild($val);
47
        }
48
        $parent->appendChild($e);
49
        return $e;
50
    }
51
52
}