ServiceProvider   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeys() 0 3 1
A getSharedKey() 0 3 1
A getPrivateKey() 0 25 5
A getEntityId() 0 3 1
A isAssertionEncryptionRequired() 0 3 1
A getCertificateData() 0 3 1
A getBlacklistedAlgorithms() 0 3 1
A getCertificateFingerprints() 0 3 1
A getCertificateFile() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Configuration;
6
7
use RuntimeException;
8
use SimpleSAML\XMLSecurity\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\Constants 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...
9
10
use function array_filter;
11
use function array_pop;
12
use function count;
13
use function sprintf;
14
15
/**
16
 * Basic Configuration Wrapper
17
 */
18
class ServiceProvider extends ArrayAdapter implements CertificateProvider, DecryptionProvider, EntityIdProvider
19
{
20
    /**
21
     * @return null|array|\Traversable
22
     */
23
    public function getKeys()
24
    {
25
        return $this->get('keys');
26
    }
27
28
29
    /**
30
     */
31
    public function getCertificateData(): ?string
32
    {
33
        return $this->get('certificateData');
34
    }
35
36
37
    /**
38
     */
39
    public function getCertificateFile(): ?string
40
    {
41
        return $this->get('certificateFile');
42
    }
43
44
45
    /**
46
     * @return array|\Traversable|null
47
     */
48
    public function getCertificateFingerprints()
49
    {
50
        return $this->get('certificateFingerprints');
51
    }
52
53
54
    /**
55
     */
56
    public function getEntityId(): ?string
57
    {
58
        return $this->get('entityId');
59
    }
60
61
62
    /**
63
     */
64
    public function isAssertionEncryptionRequired(): ?bool
65
    {
66
        return $this->get('assertionEncryptionEnabled');
67
    }
68
69
70
    /**
71
     */
72
    public function getSharedKey(): ?string
73
    {
74
        return $this->get('sharedKey');
75
    }
76
77
78
    /**
79
     * @return mixed|null
80
     */
81
    public function getPrivateKey(string $name, ?bool $required = null)
82
    {
83
        if ($required === null) {
84
            $required = false;
85
        }
86
        $privateKeys = $this->get('privateKeys');
87
        $key = array_filter($privateKeys, function (PrivateKey $key) use ($name) {
0 ignored issues
show
Bug introduced by
It seems like $privateKeys can also be of type null; however, parameter $array of array_filter() does only seem to accept array, 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

87
        $key = array_filter(/** @scrutinizer ignore-type */ $privateKeys, function (PrivateKey $key) use ($name) {
Loading history...
Bug introduced by
The type SimpleSAML\SAML2\Configuration\PrivateKey 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...
88
            return $key->getName() === $name;
89
        });
90
91
        $keyCount = count($key);
92
        if ($keyCount !== 1 && $required) {
93
            throw new RuntimeException(sprintf(
94
                'Attempted to get privateKey by name "%s", found "%d" keys, where only one was expected. Please '
95
                . 'verify that your configuration is correct',
96
                $name,
97
                $keyCount,
98
            ));
99
        }
100
101
        if (!$keyCount) {
102
            return null;
103
        }
104
105
        return array_pop($key);
106
    }
107
108
109
    /**
110
     * @return array
111
     */
112
    public function getBlacklistedAlgorithms(): array
113
    {
114
        return $this->get('blacklistedEncryptionAlgorithms', [C::KEY_TRANSPORT_RSA_1_5]);
115
    }
116
}
117