Completed
Push — develop ( bf29c8...a40a02 )
by A.
03:57 queued 15s
created

MappedInstitutionConfiguration   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 101
Duplicated Lines 26.73 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 8
dl 27
loc 101
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A inferRemoveInstitutionConfigurationByIdCommand() 8 8 1
A inferCreateInstitutionConfigurationCommand() 8 8 1
A inferReconfigureInstitutionConfigurationCommand() 0 10 1
A inferAddRaLocationCommands() 0 19 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet bv
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\StepupMiddleware\MiddlewareBundle\Migrations\InstitutionConfiguration;
20
21
use Rhumsaa\Uuid\Uuid;
22
use Surfnet\Stepup\Configuration\Entity\RaLocation;
23
use Surfnet\Stepup\Configuration\Value\Institution;
24
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption;
25
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption;
26
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand;
27
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand;
28
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ReconfigureInstitutionConfigurationOptionsCommand;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 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...
29
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveInstitutionConfigurationByUnnormalizedIdCommand;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 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...
30
31
final class MappedInstitutionConfiguration
32
{
33
    /**
34
     * @var Institution
35
     */
36
    private $institution;
37
38
    /**
39
     * @var ShowRaaContactInformationOption
40
     */
41
    private $showRaaContactInformationOption;
42
43
    /**
44
     * @var UseRaLocationsOption
45
     */
46
    private $useRaLocationsOption;
47
48
    /**
49
     * @var array|RaLocation[]
50
     */
51
    private $raLocations;
52
53
    /**
54
     * @param Institution                     $institution
55
     * @param UseRaLocationsOption            $useRaLocationsOption
56
     * @param ShowRaaContactInformationOption $showRaaContactInformationOption
57
     * @param RaLocation[]                    $raLocations
58
     */
59 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method 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...
60
        Institution $institution,
61
        UseRaLocationsOption $useRaLocationsOption,
62
        ShowRaaContactInformationOption $showRaaContactInformationOption,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $showRaaContactInformationOption 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...
63
        array $raLocations
64
    ) {
65
        $this->institution                     = $institution;
66
        $this->showRaaContactInformationOption = $showRaaContactInformationOption;
67
        $this->useRaLocationsOption            = $useRaLocationsOption;
68
        $this->raLocations                     = $raLocations;
69
    }
70
71
    /**
72
     * @return RemoveInstitutionConfigurationByUnnormalizedIdCommand
73
     */
74 View Code Duplication
    public function inferRemoveInstitutionConfigurationByIdCommand()
0 ignored issues
show
Duplication introduced by
This method 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...
75
    {
76
        $command              = new RemoveInstitutionConfigurationByUnnormalizedIdCommand();
77
        $command->UUID        = (string) Uuid::uuid4();
78
        $command->institution = $this->institution->getInstitution();
79
80
        return $command;
81
    }
82
83
    /**
84
     * @return CreateInstitutionConfigurationCommand
85
     */
86 View Code Duplication
    public function inferCreateInstitutionConfigurationCommand()
0 ignored issues
show
Duplication introduced by
This method 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...
87
    {
88
        $command              = new CreateInstitutionConfigurationCommand();
89
        $command->UUID        = (string) Uuid::uuid4();
90
        $command->institution = $this->institution->getInstitution();
91
92
        return $command;
93
    }
94
95
    /**
96
     * @return ReconfigureInstitutionConfigurationOptionsCommand
97
     */
98
    public function inferReconfigureInstitutionConfigurationCommand()
99
    {
100
        $command                                  = new ReconfigureInstitutionConfigurationOptionsCommand();
101
        $command->UUID                            = (string) Uuid::uuid4();
102
        $command->institution                     = $this->institution->getInstitution();
103
        $command->useRaLocationsOption            = $this->useRaLocationsOption->isEnabled();
104
        $command->showRaaContactInformationOption = $this->showRaaContactInformationOption->isEnabled();
105
106
        return $command;
107
    }
108
109
    /**
110
     * @return AddRaLocationCommand[]
111
     */
112
    public function inferAddRaLocationCommands()
113
    {
114
        $commands = [];
115
        $institution = $this->institution->getInstitution();
116
117
        foreach ($this->raLocations as $raLocation) {
118
            $command                     = new AddRaLocationCommand();
119
            $command->UUID               = (string) Uuid::uuid4();
120
            $command->institution        = $institution;
121
            $command->raLocationId       = $raLocation->getId()->getRaLocationId();
122
            $command->raLocationName     = $raLocation->getName()->getRaLocationName();
123
            $command->contactInformation = $raLocation->getContactInformation()->getContactInformation();
124
            $command->location           = $raLocation->getLocation()->getLocation();
125
126
            $commands[] = $command;
127
        }
128
129
        return $commands;
130
    }
131
}
132