Passed
Pull Request — master (#363)
by Tim
02:37
created

ServiceProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 11
dl 0
loc 25
rs 9.9

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\Metadata;
6
7
use SimpleSAML\Assert\Assert;
8
use SimpleSAML\SAML2\XML\md\AssertionConsumerService;
9
use SimpleSAML\XMLSecurity\Constants as C;
10
use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey};
11
12
/**
13
 * Class holding configuration for a SAML 2 Service Provider.
14
 *
15
 * @package simplesamlphp/saml2
16
 */
17
class ServiceProvider extends AbstractProvider
18
{
19
    /**
20
     */
21
    public function __construct(
22
        string $entityId,
23
        string $signatureAlgorithm = C::SIG_RSA_SHA256,
24
        array $validatingKeys = [],
25
        ?PrivateKey $signingKey = null,
26
        ?PublicKey $encryptionKey = null,
27
        protected array $assertionConsumerService = [],
28
        array $decryptionKeys = [],
29
        ?SymmetricKey $preSharedKey = null,
30
        string $preSharedKeyAlgorithm = C::BLOCK_ENC_AES256_GCM,
31
        array $IDPList = [],
32
        protected bool $wantAssertionsSigned = false, // Default false by specification
33
    ) {
34
        Assert::allIsInstanceOf($assertionConsumerService, AssertionConsumerService::class);
35
36
        parent::__construct(
37
            $entityId,
38
            $signatureAlgorithm,
39
            $validatingKeys,
40
            $signingKey,
41
            $encryptionKey,
42
            $decryptionKeys,
43
            $preSharedKey,
44
            $preSharedKeyAlgorithm,
45
            $IDPList,
46
        );
47
    }
48
49
50
    /**
51
     * Retrieve the configured ACS-endpoints for this Service Provider.
52
     *
53
     * @return array<\SimpleSAML\SAML2\XML\md\AssertionConsumerService>
54
     */
55
    public function getAssertionConsumerService(): array
56
    {
57
        return $this->assertionConsumerService;
58
    }
59
60
61
    /**
62
     * Retrieve the configured value for whether assertions must be signed.
63
     *
64
     * @return bool
65
     */
66
    public function getWantAssertionsSigned(): bool
67
    {
68
        return $this->wantAssertionsSigned;
69
    }
70
}
71