Passed
Push — master ( 8447f6...77de30 )
by Tim
01:32
created

NameIDMappingRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 50 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Excepti...VersionTooHighException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Excepti...tVersionTooLowException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
12
use SimpleSAML\SAML2\Type\SAMLDateTimeValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Type\SAMLDateTimeValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use SimpleSAML\SAML2\Type\SAMLStringValue;
14
use SimpleSAML\SAML2\XML\saml\Issuer;
15
use SimpleSAML\XML\SchemaValidatableElementInterface;
16
use SimpleSAML\XML\SchemaValidatableElementTrait;
17
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
18
use SimpleSAML\XMLSchema\Exception\MissingElementException;
19
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
20
use SimpleSAML\XMLSchema\Type\IDValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\IDValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use SimpleSAML\XMLSecurity\XML\ds\Signature;
22
23
use function array_pop;
24
use function version_compare;
25
26
/**
27
 * Class for handling SAML2 NameIDMappingRequest.
28
 *
29
 * @package simplesamlphp/saml2
30
 */
31
final class NameIDMappingRequest extends AbstractNameIDMappingRequest implements
32
    SchemaValidatableElementInterface
33
{
34
    use SchemaValidatableElementTrait;
35
36
37
    /**
38
     * Convert XML into a NameIDMappingRequest
39
     *
40
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
41
     *   if the qualified name of the supplied element is wrong
42
     */
43
    public static function fromXML(DOMElement $xml): static
44
    {
45
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
46
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
47
48
        $version = self::getAttribute($xml, 'Version', SAMLStringValue::class);
49
        Assert::true(version_compare('2.0', strval($version), '<='), RequestVersionTooLowException::class);
50
        Assert::true(version_compare('2.0', strval($version), '>='), RequestVersionTooHighException::class);
51
52
        $issuer = Issuer::getChildrenOfClass($xml);
53
        Assert::maxCount($issuer, 1, 'Only one <saml:Issuer> element is allowed.', TooManyElementsException::class);
54
55
        $extensions = Extensions::getChildrenOfClass($xml);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\Extensions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
        Assert::maxCount(
57
            $extensions,
58
            1,
59
            'Only one <samlp:Extensions> element is allowed.',
60
            TooManyElementsException::class,
61
        );
62
63
        $signature = Signature::getChildrenOfClass($xml);
64
        Assert::maxCount(
65
            $signature,
66
            1,
67
            'Only one <ds:Signature> element is allowed.',
68
            TooManyElementsException::class,
69
        );
70
71
        $nameIdPolicy = NameIDPolicy::getChildrenOfClass($xml);
72
        Assert::minCount($nameIdPolicy, 1, MissingElementException::class);
73
        Assert::maxCount($nameIdPolicy, 1, TooManyElementsException::class);
74
75
        $request = new static(
76
            self::getIdentifierFromXML($xml),
0 ignored issues
show
Bug introduced by
It seems like self::getIdentifierFromXML($xml) can also be of type null; however, parameter $identifier of SimpleSAML\SAML2\XML\sam...gRequest::__construct() does only seem to accept SimpleSAML\SAML2\XML\saml\IdentifierInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

76
            /** @scrutinizer ignore-type */ self::getIdentifierFromXML($xml),
Loading history...
77
            array_pop($nameIdPolicy),
78
            self::getAttribute($xml, 'ID', IDValue::class),
79
            array_pop($issuer),
80
            self::getAttribute($xml, 'IssueInstant', SAMLDateTimeValue::class),
81
            self::getOptionalAttribute($xml, 'Destination', SAMLAnyURIValue::class, null),
82
            self::getOptionalAttribute($xml, 'Consent', SAMLAnyURIValue::class, null),
83
            array_pop($extensions),
84
        );
85
86
        if (!empty($signature)) {
87
            $request->setSignature($signature[0]);
88
            $request->messageContainedSignatureUponConstruction = true;
89
            $request->setXML($xml);
90
        }
91
92
        return $request;
93
    }
94
}
95