Completed
Pull Request — develop (#166)
by Daan van
22:27 queued 19:06
created

inferAddRaLocationCommands()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 0
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
     * @var ShowRaaContactInformationOption
39
     */
40
    private $showRaaContactInformationOption;
41
    /**
42
     * @var UseRaLocationsOption
43
     */
44
    private $useRaLocationsOption;
45
    /**
46
     * @var array|RaLocation[]
47
     */
48
    private $raLocations;
49
50
    /**
51
     * @param Institution                     $institution
52
     * @param UseRaLocationsOption            $useRaLocationsOption
53
     * @param ShowRaaContactInformationOption $showRaaContactInformationOption
54
     * @param RaLocation[]                    $raLocations
55
     */
56 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...
57
        Institution $institution,
58
        UseRaLocationsOption $useRaLocationsOption,
59
        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...
60
        array $raLocations
61
    ) {
62
        $this->institution                     = $institution;
63
        $this->showRaaContactInformationOption = $showRaaContactInformationOption;
64
        $this->useRaLocationsOption            = $useRaLocationsOption;
65
        $this->raLocations                     = $raLocations;
66
    }
67
68
    /**
69
     * @return RemoveInstitutionConfigurationByUnnormalizedIdCommand
70
     */
71 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...
72
    {
73
        $command              = new RemoveInstitutionConfigurationByUnnormalizedIdCommand();
74
        $command->UUID        = (string) Uuid::uuid4();
75
        $command->institution = $this->institution->getInstitution();
76
77
        return $command;
78
    }
79
80
    /**
81
     * @return CreateInstitutionConfigurationCommand
82
     */
83 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...
84
    {
85
        $command              = new CreateInstitutionConfigurationCommand();
86
        $command->UUID        = Uuid::uuid4();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Rhumsaa\Uuid\Uuid::uuid4() of type object<Rhumsaa\Uuid\Uuid> is incompatible with the declared type string of property $UUID.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
87
        $command->institution = $this->institution->getInstitution();
88
89
        return $command;
90
    }
91
92
    /**
93
     * @return ReconfigureInstitutionConfigurationOptionsCommand
94
     */
95
    public function inferReconfigureInstitutionConfigurationCommand()
96
    {
97
        $command                                  = new ReconfigureInstitutionConfigurationOptionsCommand();
98
        $command->UUID                            = (string) Uuid::uuid4();
99
        $command->institution                     = $this->institution->getInstitution();
100
        $command->useRaLocationsOption            = $this->useRaLocationsOption->isEnabled();
101
        $command->showRaaContactInformationOption = $this->showRaaContactInformationOption->isEnabled();
102
103
        return $command;
104
    }
105
106
    /**
107
     * @return AddRaLocationCommand[]
108
     */
109
    public function inferAddRaLocationCommands()
110
    {
111
        $commands = [];
112
        $institution = $this->institution->getInstitution();
113
114
        foreach ($this->raLocations as $raLocation) {
115
            $command                     = new AddRaLocationCommand();
116
            $command->UUID               = (string) Uuid::uuid4();
117
            $command->institution        = $institution;
118
            $command->raLocationId       = $raLocation->getId()->getRaLocationId();
119
            $command->raLocationName     = $raLocation->getName()->getRaLocationName();
120
            $command->contactInformation = $raLocation->getContactInformation()->getContactInformation();
121
            $command->location           = $raLocation->getLocation()->getLocation();
122
123
            $commands[] = $command;
124
        }
125
126
        return $commands;
127
    }
128
}
129