Passed
Push — master ( 691bbc...78e48b )
by Tim
01:42
created

ManageNameIDResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 19
rs 9.9666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\XMLSchema\Type\NCNameValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\NCNameValue 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...
22
use SimpleSAML\XMLSecurity\XML\ds\Signature;
23
24
use function array_pop;
25
use function strval;
26
27
/**
28
 * Class for SAML 2 ManageNameIDResponse messages.
29
 *
30
 * @package simplesamlphp/saml2
31
 */
32
class ManageNameIDResponse extends AbstractStatusResponse implements SchemaValidatableElementInterface
33
{
34
    use SchemaValidatableElementTrait;
35
36
37
    /**
38
     * Constructor for SAML 2 response messages.
39
     *
40
     * @param \SimpleSAML\XMLSchema\Type\IDValue $id
41
     * @param \SimpleSAML\SAML2\XML\samlp\Status $status
42
     * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue $issueInstant
43
     * @param \SimpleSAML\SAML2\XML\saml\Issuer|null $issuer
44
     * @param \SimpleSAML\XMLSchema\Type\NCNameValue|null $inResponseTo
45
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $destination
46
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $consent
47
     * @param \SimpleSAML\SAML2\XML\samlp\Extensions $extensions
48
     */
49
    final public function __construct(
50
        IDValue $id,
51
        Status $status,
52
        SAMLDateTimeValue $issueInstant,
53
        ?Issuer $issuer = null,
54
        ?NCNameValue $inResponseTo = null,
55
        ?SAMLAnyURIValue $destination = null,
56
        ?SAMLAnyURIValue $consent = null,
57
        ?Extensions $extensions = null,
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...
58
    ) {
59
        parent::__construct(
60
            $id,
61
            $status,
62
            $issueInstant,
63
            $issuer,
64
            $inResponseTo,
65
            $destination,
66
            $consent,
67
            $extensions,
68
        );
69
    }
70
71
72
    /**
73
     * Convert XML into a ManageNameIDResponse element.
74
     *
75
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
76
     *   if the qualified name of the supplied element is wrong
77
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
78
     *   if the supplied element is missing one of the mandatory attributes
79
     * @throws \SimpleSAML\XMLSchema\Exception\MissingElementException
80
     *   if one of the mandatory child-elements is missing
81
     */
82
    public static function fromXML(DOMElement $xml): static
83
    {
84
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
85
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
86
87
        $version = self::getAttribute($xml, 'Version', SAMLStringValue::class);
88
        Assert::true(version_compare('2.0', strval($version), '<='), RequestVersionTooLowException::class);
89
        Assert::true(version_compare('2.0', strval($version), '>='), RequestVersionTooHighException::class);
90
91
        $signature = Signature::getChildrenOfClass($xml);
92
        Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.', TooManyElementsException::class);
93
94
        $issuer = Issuer::getChildrenOfClass($xml);
95
        Assert::countBetween($issuer, 0, 1);
96
97
        $status = Status::getChildrenOfClass($xml);
98
        Assert::minCount($status, 1, MissingElementException::class);
99
        Assert::maxCount($status, 1, TooManyElementsException::class);
100
101
        $extensions = Extensions::getChildrenOfClass($xml);
102
        Assert::maxCount(
103
            $extensions,
104
            1,
105
            'Only one saml:Extensions element is allowed.',
106
            TooManyElementsException::class,
107
        );
108
109
        $response = new static(
110
            self::getAttribute($xml, 'ID', IDValue::class),
111
            array_pop($status),
112
            self::getAttribute($xml, 'IssueInstant', SAMLDateTimeValue::class),
113
            empty($issuer) ? null : array_pop($issuer),
114
            self::getOptionalAttribute($xml, 'InResponseTo', NCNameValue::class, null),
115
            self::getOptionalAttribute($xml, 'Destination', SAMLAnyURIValue::class, null),
116
            self::getOptionalAttribute($xml, 'Consent', SAMLAnyURIValue::class, null),
117
            empty($extensions) ? null : array_pop($extensions),
118
        );
119
120
        if (!empty($signature)) {
121
            $response->setSignature($signature[0]);
122
            $response->messageContainedSignatureUponConstruction = true;
123
            $response->setXML($xml);
124
        }
125
126
        return $response;
127
    }
128
}
129