Completed
Push — feature/update-institution-con... ( a9652d...ace849 )
by A.
04:00
created

handleConfigureInstitutionConfigurationOptionsCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 1
eloc 11
nc 1
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\StepupMiddleware\CommandHandlingBundle\Configuration\CommandHandler;
20
21
use Broadway\CommandHandling\CommandHandler;
22
use Broadway\Repository\RepositoryInterface;
23
use Surfnet\Stepup\Configuration\InstitutionConfiguration;
24
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId;
25
use Surfnet\Stepup\Configuration\Value\Institution;
26
use Surfnet\Stepup\Configuration\Value\Location;
27
use Surfnet\Stepup\Configuration\Value\RaLocationId;
28
use Surfnet\Stepup\Configuration\Value\RaLocationName;
29
use Surfnet\Stepup\Configuration\Value\ContactInformation;
30
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption;
31
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand;
33
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ChangeRaLocationCommand;
34
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ConfigureInstitutionConfigurationOptionsCommand;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
35
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ConfigureShowRaaContactInformationOptionCommand;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
36
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ConfigureUseRaLocationsOptionCommand;
37
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand;
38
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveRaLocationCommand;
39
40
/**
41
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects) Value objects
42
 */
43
class InstitutionConfigurationCommandHandler extends CommandHandler
44
{
45
    /**
46
     * @var RepositoryInterface
47
     */
48
    private $repository;
49
50
    public function __construct(RepositoryInterface $repository)
51
    {
52
        $this->repository = $repository;
53
    }
54
55
    public function handleCreateInstitutionConfigurationCommand(CreateInstitutionConfigurationCommand $command)
56
    {
57
        $institution                = new Institution($command->institution);
58
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
59
        $institutionConfiguration   = InstitutionConfiguration::create($institutionConfigurationId, $institution);
60
61
        $this->repository->save($institutionConfiguration);
62
    }
63
64 View Code Duplication
    public function handleConfigureInstitutionConfigurationOptionsCommand(
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...
65
        ConfigureInstitutionConfigurationOptionsCommand $command
66
    ) {
67
        $institution                = new Institution($command->institution);
68
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
69
70
        $institutionConfiguration = $this->repository->load(
71
            $institutionConfigurationId->getInstitutionConfigurationId()
72
        );
73
74
        $institutionConfiguration->configureUseRaLocationsOption(
75
            new UseRaLocationsOption($command->useRaLocationsOption)
76
        );
77
        $institutionConfiguration->configureShowRaaContactInformationOption(
78
            new ShowRaaContactInformationOption($command->showRaaContactInformationOption)
79
        );
80
81
        $this->repository->save($institutionConfiguration);
82
    }
83
84 View Code Duplication
    public function handleConfigureUseRaLocationsOptionCommand(ConfigureUseRaLocationsOptionCommand $command)
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...
85
    {
86
        $institution = new Institution($command->institution);
87
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
88
89
        $institutionConfiguration = $this->repository->load(
90
            $institutionConfigurationId->getInstitutionConfigurationId()
91
        );
92
93
        $institutionConfiguration->configureUseRaLocationsOption(
94
            new UseRaLocationsOption($command->useRaLocationsOption)
95
        );
96
97
        $this->repository->save($institutionConfiguration);
98
    }
99
100 View Code Duplication
    public function handleConfigureShowRaaContactInformationOptionCommand(
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...
101
        ConfigureShowRaaContactInformationOptionCommand $command
102
    ) {
103
        $institution = new Institution($command->institution);
104
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
105
106
        $institutionConfiguration = $this->repository->load(
107
            $institutionConfigurationId->getInstitutionConfigurationId()
108
        );
109
110
        $institutionConfiguration->configureShowRaaContactInformationOption(
111
            new ShowRaaContactInformationOption($command->showRaaContactInformationOption)
112
        );
113
114
        $this->repository->save($institutionConfiguration);
115
    }
116
117 View Code Duplication
    public function handleAddRaLocationCommand(AddRaLocationCommand $command)
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...
118
    {
119
        $institution                = new Institution($command->institution);
120
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
121
122
        $institutionConfiguration = $this->repository->load(
123
            $institutionConfigurationId->getInstitutionConfigurationId()
124
        );
125
126
        $institutionConfiguration->addRaLocation(
127
            new RaLocationId($command->raLocationId),
128
            new RaLocationName($command->raLocationName),
129
            new Location($command->location),
130
            new ContactInformation($command->contactInformation)
131
        );
132
133
        $this->repository->save($institutionConfiguration);
134
    }
135
136 View Code Duplication
    public function handleChangeRaLocationCommand(ChangeRaLocationCommand $command)
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...
137
    {
138
        $institution                = new Institution($command->institution);
139
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
140
141
        $institutionConfiguration = $this->repository->load(
142
            $institutionConfigurationId->getInstitutionConfigurationId()
143
        );
144
145
        $institutionConfiguration->changeRaLocation(
146
            new RaLocationId($command->raLocationId),
147
            new RaLocationName($command->raLocationName),
148
            new Location($command->location),
149
            new ContactInformation($command->contactInformation)
150
        );
151
152
        $this->repository->save($institutionConfiguration);
153
    }
154
155
    public function handleRemoveRaLocationCommand(RemoveRaLocationCommand $command)
156
    {
157
        $institution                = new Institution($command->institution);
158
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
159
160
        $institutionConfiguration = $this->repository->load(
161
            $institutionConfigurationId->getInstitutionConfigurationId()
162
        );
163
164
        $institutionConfiguration->removeRaLocation(new RaLocationId($command->raLocationId));
165
166
        $this->repository->save($institutionConfiguration);
167
    }
168
}
169