Completed
Push — master ( cf3f06...ee1dbf )
by Daan van
06:20 queued 02:45
created

getInstitutionConfigurationOptionsFor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 17
Ratio 85 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 17
loc 20
rs 9.4285
cc 3
eloc 11
nc 3
nop 1
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\StepupMiddlewareClientBundle\Configuration\Service;
20
21
use Surfnet\StepupMiddlewareClient\Configuration\Service\InstitutionConfigurationOptionsService as LibraryInstitutionConfigurationOptionsService;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
22
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions;
23
use Surfnet\StepupMiddlewareClientBundle\Exception\InvalidResponseException;
24
use Symfony\Component\Validator\Validator\ValidatorInterface;
25
26 View Code Duplication
final class InstitutionConfigurationOptionsService
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
{
28
    /**
29
     * @var LibraryInstitutionConfigurationOptionsService
30
     */
31
    private $service;
32
    /**
33
     * @var ValidatorInterface
34
     */
35
    private $validator;
36
37
    public function __construct(LibraryInstitutionConfigurationOptionsService $service, ValidatorInterface $validator)
38
    {
39
        $this->service   = $service;
40
        $this->validator = $validator;
41
    }
42
43
    /**
44
     * @param $institution
45
     * @return null|InstitutionConfigurationOptions
46
     */
47
    public function getInstitutionConfigurationOptionsFor($institution)
48
    {
49
        $data = $this->service->getInstitutionConfigurationOptionsFor($institution);
50
51
        if ($data === null) {
52
            return null;
53
        }
54
55
        $institutionConfigurationOptions = InstitutionConfigurationOptions::fromData($data);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptions exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
56
57
        $violations = $this->validator->validate($institutionConfigurationOptions);
58
        if (count($violations) > 0) {
59
            throw InvalidResponseException::withViolations(
60
                sprintf('Could not get institution configuration options for "%s": invalid response', $institution),
61
                $violations
62
            );
63
        }
64
65
        return $institutionConfigurationOptions;
66
    }
67
}
68