Passed
Push — master ( c6f9d9...f007cf )
by Marek
02:20
created

EidasRequestedAttributes   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 8 2
A __construct() 0 11 5
1
<?php
2
3
namespace OMSAML2\Chunks;
4
5
use DOMElement;
6
use SAML2\XML\Chunk;
7
8
class EidasRequestedAttributes extends Chunk
9
{
10
11
    const NS_EIDAS = 'http://eidas.europa.eu/saml-extensions';
12
    const LOCAL_NAME = 'RequestedAttributes';
13
    /**@var $requested_attributes EidasRequestedAttribute[] */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $requested_attributes at position 0 could not be parsed: Unknown type name '$requested_attributes' at position 0 in $requested_attributes.
Loading history...
14
    public $requested_attributes = [];
15
16
    public function __construct(DOMElement $xml = null)
17
    {
18
        if (!empty($xml) && $xml->localName != self::LOCAL_NAME) {
19
            $xml = $xml->ownerDocument->getElementsByTagNameNS(self::NS_EIDAS, self::LOCAL_NAME)->item(0);
20
        }
21
        if (empty($xml)) {
22
            return;
23
        }
24
        parent::__construct($xml);
25
        foreach ($xml->getElementsByTagNameNS(self::NS_EIDAS, EidasRequestedAttribute::LOCAL_NAME) as $requestedAttr) {
26
            $this->requested_attributes[] = new EidasRequestedAttribute($requestedAttr);
27
        }
28
    }
29
30
    public function toXML(DOMElement $parent): DOMElement
31
    {
32
        $e = $parent->ownerDocument->createElementNS(self::NS_EIDAS, self::LOCAL_NAME);
33
        foreach ($this->requested_attributes as $attribute) {
34
            $attribute->toXML($e);
35
        }
36
        $parent->appendChild($e);
37
        return $e;
38
    }
39
}