Completed
Pull Request — develop (#225)
by
unknown
09:12 queued 07:20
created

RemoteVettingConfiguration   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 3
dl 0
loc 75
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 24 2
A getLocation() 0 4 1
A getPublicKey() 0 4 1
A getRemoteVettingIdps() 0 4 1
A getRemoteVettingIdp() 0 8 2
A getAttributeMapping() 0 8 2
1
<?php
2
3
/**
4
 * Copyright 2020 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Configuration;
20
21
use Surfnet\StepupSelfService\SelfServiceBundle\Assert;
22
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\InvalidRemoteVettingIdentityProviderException;
23
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Dto\RemoteVettingIdenityProviderDto;
24
25
class RemoteVettingConfiguration
26
{
27
    private $publicKey;
28
29
    private $location;
30
31
    private $idps = [];
32
33
    private $attributeMapping = [];
34
35
    public function __construct(string $privateKey, array $configurationSettings, array $remoteVettingIdpConfig)
36
    {
37
        Assert::string($privateKey, 'privateKey should be a string');
38
        Assert::file($privateKey, 'privateKey should be a file');
39
40
        Assert::string($configurationSettings['encryption_public_key'], 'identity_encryption_configuration.encryption_public_key should be a string');
41
        Assert::string($configurationSettings['storage_location'], 'identity_encryption_configuration.storage_location should be a string');
42
43
        $this->publicKey = $configurationSettings['encryption_public_key'];
44
        $this->location = $configurationSettings['storage_location'];
45
46
        foreach ($remoteVettingIdpConfig as $idpConfig) {
47
            $idpConfig['privateKey'] = $privateKey;
48
49
            $idp = RemoteVettingIdenityProviderDto::create($idpConfig);
50
            $this->idps[$idp->getSlug()] = $idp;
51
52
            Assert::keyExists($idpConfig, 'attributeMapping', sprintf('attributeMapping should be set: %s', $idp->getSlug()));
53
            Assert::isArray($idpConfig['attributeMapping'], 'attributeMapping should be an array');
54
            Assert::allString($idpConfig['attributeMapping'], 'attributeMapping should consist of strings');
55
56
            $this->attributeMapping[$idp->getSlug()] = $idpConfig['attributeMapping'];
57
        }
58
    }
59
60
    public function getLocation()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
61
    {
62
        return $this->location;
63
    }
64
65
    public function getPublicKey()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
66
    {
67
        return $this->publicKey;
68
    }
69
70
    /**
71
     * @return RemoteVettingIdenityProviderDto[]
72
     */
73
    public function getRemoteVettingIdps(): array
74
    {
75
        return $this->idps;
76
    }
77
78
    public function getRemoteVettingIdp(string $name): RemoteVettingIdenityProviderDto
79
    {
80
        if (array_key_exists($name, $this->idps)) {
81
            return $this->idps[$name];
82
        }
83
84
        throw new InvalidRemoteVettingIdentityProviderException(sprintf("Invalid IdP requested '%s'", $name));
85
    }
86
87
    /**
88
     * @param string
89
     * @return array
90
     */
91
    public function getAttributeMapping($name)
92
    {
93
        if (array_key_exists($name, $this->attributeMapping)) {
94
            return $this->attributeMapping[$name];
95
        }
96
97
        throw new InvalidRemoteVettingIdentityProviderException(sprintf("Invalid IdP requested '%s'", $name));
98
    }
99
}
100