Issuer::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SPID\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML2\Constants as C;
10
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
11
use SimpleSAML\SAML2\Type\SAMLStringValue;
12
use SimpleSAML\SAML2\XML\saml\NameIDType;
13
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14
15
/**
16
 * Class representing the saml:Issuer element compliant with SPID specification.
17
 *
18
 * @package simplesamlphp/saml2-module-spid
19
 */
20
final class Issuer extends NameIDType
21
{
22
    /**
23
     * Initialize a saml:Issuer conforming to SPID specification
24
     *
25
     * @param \SimpleSAML\SAML2\Type\SAMLStringValue $value
26
     * @param \SimpleSAML\SAML2\Type\SAMLStringValue $NameQualifier
27
     */
28
    public function __construct(
29
        SAMLStringValue $value,
30
        SAMLStringValue $NameQualifier,
31
    ) {
32
        parent::__construct($value, $NameQualifier, null, SAMLAnyURIValue::fromString(C::NAMEID_ENTITY));
33
    }
34
35
36
    /**
37
     * Convert XML into an Issuer
38
     *
39
     * @param \DOMElement $xml The XML element we should load
40
     *
41
     * @return static
42
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
43
     */
44
    public static function fromXML(DOMElement $xml): static
45
    {
46
        Assert::same($xml->localName, 'Issuer', InvalidDOMElementException::class);
47
        Assert::same($xml->namespaceURI, Issuer::NS, InvalidDOMElementException::class);
48
49
        $format = self::getAttribute($xml, 'Format', SAMLAnyURIValue::class);
50
        Assert::true($format->equals(C::NAMEID_ENTITY));
0 ignored issues
show
Bug introduced by
The method equals() does not exist on SimpleSAML\XMLSchema\Typ...face\ValueTypeInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SimpleSAML\XMLSchema\Typ...rface\ListTypeInterface or SimpleSAML\XMLSchema\Typ...\AttributeTypeInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        Assert::true($format->/** @scrutinizer ignore-call */ equals(C::NAMEID_ENTITY));
Loading history...
51
52
        return new static(
53
            SAMLStringValue::fromString($xml->textContent),
54
            self::getAttribute($xml, 'NameQualifier', SAMLStringValue::class),
55
        );
56
    }
57
}
58