Passed
Pull Request — master (#6)
by Tim
02:20
created

BindingOperationOutput   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 1
b 0
f 0
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsdl;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Chunk;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
12
/**
13
 * Class representing the Output element.
14
 *
15
 * @package simplesamlphp/ws-security
16
 */
17
final class BindingOperationOutput extends AbstractBindingOperationMessage
18
{
19
    /** @var string */
20
    final public const LOCALNAME = 'output';
21
22
23
    /**
24
     * Initialize a Output element.
25
     *
26
     * @param \DOMElement $xml The XML element we should load.
27
     * @return static
28
     *
29
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
30
     *   if the qualified name of the supplied element is wrong
31
     */
32
    public static function fromXML(DOMElement $xml): static
33
    {
34
        Assert::same($xml->localName, static::LOCALNAME, InvalidDOMElementException::class);
35
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
36
37
        $children = [];
38
        foreach ($xml->childNodes as $child) {
39
            if (!($child instanceof DOMElement)) {
40
                continue;
41
            } elseif ($child->namespaceURI === static::NS) {
42
                // Only other namespaces are allowed
43
                continue;
44
            }
45
46
            $children[] = new Chunk($child);
47
        }
48
49
        return new static(
50
            self::getOptionalAttribute($xml, 'name', null),
51
            $children,
52
        );
53
    }
54
}
55