Passed
Push — master ( fb0d53...7c0351 )
by Jaime Pérez
03:11
created

IdentityProvider::getCertificateFingerprints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SAML2\Configuration;
4
5
/**
6
 * Basic configuration wrapper
7
 */
8
class IdentityProvider extends ArrayAdapter implements
9
    CertificateProvider,
10
    DecryptionProvider,
11
    EntityIdProvider
12
{
13
    /**
14
     * @return mixed
15
     */
16
    public function getKeys()
17
    {
18
        return $this->get('keys');
19
    }
20
21
22
    /**
23
     * @return mixed
24
     */
25
    public function getCertificateData()
26
    {
27
        return $this->get('certificateData');
28
    }
29
30
31
    /**
32
     * @return mixed
33
     */
34
    public function getCertificateFile()
35
    {
36
        return $this->get('certificateFile');
37
    }
38
39
    public function isAssertionEncryptionRequired()
40
    {
41
        return $this->get('assertionEncryptionEnabled');
42
    }
43
44
45
    /**
46
     * @return mixed
47
     */
48
    public function getSharedKey()
49
    {
50
        return $this->get('sharedKey');
51
    }
52
53
54
    /**
55
     * @return mixed
56
     */
57
    public function hasBase64EncodedAttributes()
58
    {
59
        return $this->get('base64EncodedAttributes');
60
    }
61
62
63
    /**
64
     * @param string $name
65
     * @param bool $required
66
     * @return mixed|null
67
     */
68
    public function getPrivateKey($name, $required = false)
69
    {
70
        $privateKeys = $this->get('privateKeys');
71
        $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 $input 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

71
        $key = array_filter(/** @scrutinizer ignore-type */ $privateKeys, function (PrivateKey $key) use ($name) {
Loading history...
72
            return $key->getName() === $name;
73
        });
74
75
        $keyCount = count($key);
76
        if ($keyCount !== 1 && $required) {
77
            throw new \RuntimeException(sprintf(
78
                'Attempted to get privateKey by name "%s", found "%d" keys, where only one was expected. Please '
79
                . 'verify that your configuration is correct',
80
                $name,
81
                $keyCount
82
            ));
83
        }
84
85
        if (!$keyCount) {
86
            return null;
87
        }
88
89
        return array_pop($key);
90
    }
91
92
93
    /**
94
     * @return mixed
95
     */
96
    public function getBlacklistedAlgorithms()
97
    {
98
        return $this->get('blacklistedEncryptionAlgorithms');
99
    }
100
101
102
    /**
103
     * @return mixed
104
     */
105
    public function getEntityId()
106
    {
107
        return $this->get('entityId');
108
    }
109
}
110