Passed
Push — master ( e8d72a...c36ad9 )
by Tim
02:38
created

SubjectConfirmationData::isEmptyElement()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 7
nc 7
nop 0
dl 0
loc 9
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Type\EntityIDValue;
10
use SimpleSAML\SAML2\Type\SAMLDateTimeValue;
11
use SimpleSAML\SAML2\Type\SAMLStringValue;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
use SimpleSAML\XMLSchema\Type\NCNameValue;
16
17
/**
18
 * Class representing SAML 2 SubjectConfirmationData element.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class SubjectConfirmationData extends AbstractSubjectConfirmationData implements SchemaValidatableElementInterface
23
{
24
    use SchemaValidatableElementTrait;
25
26
27
    /**
28
     * Convert XML into a SubjectConfirmationData
29
     *
30
     * @param \DOMElement $xml The XML element we should load
31
     * @return static
32
     *
33
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
34
     *   if the qualified name of the supplied element is wrong
35
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
36
     *   if the supplied element is missing any of the mandatory attributes
37
     * @throws \SimpleSAML\Assert\AssertionFailedException
38
     *   if NotBefore or NotOnOrAfter contain an invalid date.
39
     */
40
    public static function fromXML(DOMElement $xml): static
41
    {
42
        Assert::same($xml->localName, 'SubjectConfirmationData', InvalidDOMElementException::class);
43
        Assert::same($xml->namespaceURI, SubjectConfirmationData::NS, InvalidDOMElementException::class);
44
45
        return new static(
46
            self::getOptionalAttribute($xml, 'NotBefore', SAMLDateTimeValue::class, null),
47
            self::getOptionalAttribute($xml, 'NotOnOrAfter', SAMLDateTimeValue::class, null),
48
            self::getOptionalAttribute($xml, 'Recipient', EntityIDValue::class, null),
49
            self::getOptionalAttribute($xml, 'InResponseTo', NCNameValue::class, null),
50
            self::getOptionalAttribute($xml, 'Address', SAMLStringValue::class, null),
51
            self::getChildElementsFromXML($xml),
52
            self::getAttributesNSFromXML($xml),
53
        );
54
    }
55
}
56