InstitutionConfigurationOptionsService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstitutionConfigurationOptionsFor() 0 23 5
1
<?php
2
3
/**
4
 * Copyright 2016 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\StepupRa\RaBundle\Service;
20
21
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions;
22
use Surfnet\StepupMiddlewareClientBundle\Configuration\Service\InstitutionConfigurationOptionsService as ApiInstitutionConfigurationOptionsService;
23
use Surfnet\StepupRa\RaBundle\Exception\RuntimeException;
24
25
final class InstitutionConfigurationOptionsService implements InstitutionConfigurationOptionsServiceInterface
26
{
27
    /**
28
     * @var ApiInstitutionConfigurationOptionsService
29
     */
30
    private $apiInstitutionConfigurationOptionsService;
31
32
    public function __construct(ApiInstitutionConfigurationOptionsService $apiService)
33
    {
34
        $this->apiInstitutionConfigurationOptionsService = $apiService;
35
    }
36
37
    /**
38
     * @param string $institution
39
     * @return null|InstitutionConfigurationOptions
40
     */
41
    public function getInstitutionConfigurationOptionsFor($institution)
42
    {
43
        $configuration = $this->apiInstitutionConfigurationOptionsService->getInstitutionConfigurationOptionsFor($institution);
44
45
        if (!$configuration) {
46
            throw new RuntimeException(sprintf('Unable to load the institution configuration for "%s"', $institution));
47
        }
48
49
        // If the FGA options are null (which they may be) then set them with the default value. This is the own institution.
50
        if (is_null($configuration->useRa)) {
51
            $configuration->useRa = [$institution];
52
        }
53
54
        if (is_null($configuration->useRaa)) {
55
            $configuration->useRaa = [$institution];
56
        }
57
58
        if (is_null($configuration->selectRaa)) {
59
            $configuration->selectRaa = [$institution];
60
        }
61
62
        return $configuration;
63
    }
64
}
65