Passed
Push — master ( 25fd26...1cb796 )
by Jaime Pérez
02:17
created

NameID::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\XML\saml;
6
7
use DOMElement;
8
use Webmozart\Assert\Assert;
9
10
/**
11
 * Class representing the saml:NameID element.
12
 *
13
 * @author Jaime Pérez Crespo, UNINETT AS <[email protected]>
14
 * @package SimpleSAMLphp
15
 */
16
final class NameID extends NameIDType
17
{
18
    /**
19
     * Initialize a saml:NameID
20
     *
21
     * @param string $value
22
     * @param string|null $NameQualifier
23
     * @param string|null $SPNameQualifier
24
     * @param string|null $Format
25
     * @param string|null $SPProvidedID
26
     */
27
    public function __construct(
28
        string $value,
29
        ?string $NameQualifier = null,
30
        ?string $SPNameQualifier = null,
31
        ?string $Format = null,
32
        ?string $SPProvidedID = null
33
    ) {
34
        parent::__construct($value, $NameQualifier, $SPNameQualifier, $Format, $SPProvidedID);
35
    }
36
37
38
    /**
39
     * Convert XML into an NameID
40
     *
41
     * @param \DOMElement $xml The XML element we should load
42
     *
43
     * @return self
44
     * @throws \InvalidArgumentException
45
     */
46
    public static function fromXML(DOMElement $xml): object
47
    {
48
        Assert::same($xml->localName, 'NameID');
49
        Assert::same($xml->namespaceURI, NameID::NS);
50
51
        $NameQualifier = self::getAttribute($xml, 'NameQualifier', null);
52
        $SPNameQualifier = self::getAttribute($xml, 'SPNameQualifier', null);
53
        $Format = self::getAttribute($xml, 'Format', null);
54
        $SPProvidedID = self::getAttribute($xml, 'SPProvidedID', null);
55
56
        return new self($xml->textContent, $NameQualifier, $SPNameQualifier, $Format, $SPProvidedID);
57
    }
58
}
59