Passed
Push — master ( 6db269...70aff8 )
by Jaime Pérez
02:49
created

Extensions::fromXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\XML\samlp;
6
7
use DOMElement;
8
use SAML2\ExtensionsTrait;
9
use SAML2\Utils;
10
use SAML2\XML\Chunk;
11
use Webmozart\Assert\Assert;
12
13
/**
14
 * Class for handling SAML2 extensions.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
final class Extensions extends AbstractSamlpElement
19
{
20
    use ExtensionsTrait;
21
22
    /**
23
     * Create an Extensions object from its md:Extensions XML representation.
24
     *
25
     * For those supported extensions, an object of the corresponding class will be created. The rest will be added
26
     * as a \SAML2\XML\Chunk object.
27
     *
28
     * @param \DOMElement $xml
29
     * @return \SAML2\XML\md\Extensions
30
     * @throws \InvalidArgumentException if the qualified name of the supplied element is wrong
31
     */
32
    public static function fromXML(DOMElement $xml): object
33
    {
34
        Assert::eq(
35
            $xml->namespaceURI,
36
            self::NS,
37
            'Unknown namespace \'' . strval($xml->namespaceURI) . '\' for Extensions element.'
38
        );
39
        Assert::eq(
40
            $xml->localName,
41
            static::getClassName(static::class),
42
            'Invalid Extensions element \'' . $xml->localName . '\''
43
        );
44
        $ret = [];
45
46
        /** @var \DOMElement $node */
47
        foreach (Utils::xpQuery($xml, './*') as $node) {
48
            $ret[] = new Chunk($node);
49
        }
50
51
        return new self($ret);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new self($ret) returns the type SAML2\XML\samlp\Extensions which is incompatible with the documented return type SAML2\XML\md\Extensions.
Loading history...
52
    }
53
}
54