Passed
Push — master ( 78e48b...97e118 )
by Tim
01:34
created

ManageNameIDRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 59 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\SAML2\XML\samlp\NewEncryptedID;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\NewEncryptedID 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...
16
use SimpleSAML\SAML2\XML\samlp\NewID;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\NewID 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...
17
use SimpleSAML\SAML2\XML\samlp\Terminate;
18
use SimpleSAML\XML\SchemaValidatableElementInterface;
19
use SimpleSAML\XML\SchemaValidatableElementTrait;
20
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
21
use SimpleSAML\XMLSchema\Exception\MissingElementException;
22
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
23
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...
24
use SimpleSAML\XMLSecurity\XML\ds\Signature;
25
26
use function array_merge;
27
use function array_pop;
28
use function version_compare;
29
30
/**
31
 * Class for handling SAML2 ManageNameIDRequest.
32
 *
33
 * @package simplesamlphp/saml2
34
 */
35
final class ManageNameIDRequest extends AbstractManageNameIDRequest implements
36
    SchemaValidatableElementInterface
37
{
38
    use SchemaValidatableElementTrait;
39
40
41
    /**
42
     * Convert XML into a ManageNameIDRequest
43
     *
44
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
45
     *   if the qualified name of the supplied element is wrong
46
     */
47
    public static function fromXML(DOMElement $xml): static
48
    {
49
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
50
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
51
52
        $version = self::getAttribute($xml, 'Version', SAMLStringValue::class);
53
        Assert::true(version_compare('2.0', strval($version), '<='), RequestVersionTooLowException::class);
54
        Assert::true(version_compare('2.0', strval($version), '>='), RequestVersionTooHighException::class);
55
56
        $issuer = Issuer::getChildrenOfClass($xml);
57
        Assert::maxCount($issuer, 1, 'Only one <saml:Issuer> element is allowed.', TooManyElementsException::class);
58
59
        $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...
60
        Assert::maxCount(
61
            $extensions,
62
            1,
63
            'Only one <samlp:Extensions> element is allowed.',
64
            TooManyElementsException::class,
65
        );
66
67
        $signature = Signature::getChildrenOfClass($xml);
68
        Assert::maxCount(
69
            $signature,
70
            1,
71
            'Only one <ds:Signature> element is allowed.',
72
            TooManyElementsException::class,
73
        );
74
75
        $newId = NewID::getChildrenOfClass($xml);
76
        Assert::maxCount($newId, 1, TooManyElementsException::class);
77
78
        $newEncryptedId = NewEncryptedID::getChildrenOfClass($xml);
79
        Assert::maxCount($newEncryptedId, 1, TooManyElementsException::class);
80
81
        $terminate = Terminate::getChildrenOfClass($xml);
82
        Assert::maxCount($terminate, 1, TooManyElementsException::class);
83
84
        $newIdentifier = array_merge($newId, $newEncryptedId, $terminate);
85
        Assert::minCount($newIdentifier, 1, MissingElementException::class);
86
        Assert::maxCount($newIdentifier, 1, TooManyElementsException::class);
87
88
        $request = new static(
89
            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...DRequest::__construct() does only seem to accept SimpleSAML\SAML2\XML\sam...L\SAML2\XML\saml\NameID, 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

89
            /** @scrutinizer ignore-type */ self::getIdentifierFromXML($xml),
Loading history...
90
            array_pop($newIdentifier),
91
            self::getAttribute($xml, 'ID', IDValue::class),
92
            array_pop($issuer),
93
            self::getAttribute($xml, 'IssueInstant', SAMLDateTimeValue::class),
94
            self::getOptionalAttribute($xml, 'Destination', SAMLAnyURIValue::class, null),
95
            self::getOptionalAttribute($xml, 'Consent', SAMLAnyURIValue::class, null),
96
            array_pop($extensions),
97
        );
98
99
        if (!empty($signature)) {
100
            $request->setSignature($signature[0]);
101
            $request->messageContainedSignatureUponConstruction = true;
102
            $request->setXML($xml);
103
        }
104
105
        return $request;
106
    }
107
}
108