Completed
Push — feature/create-institution-con... ( c6588d...733225 )
by A.
03:50
created

InstitutionConfigurationCommandHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 49.32 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 7
Bugs 0 Features 4
Metric Value
wmc 5
c 7
b 0
f 4
lcom 1
cbo 13
dl 36
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleCreateInstitutionConfigurationCommand() 0 8 1
A handleAddRaLocationCommand() 18 18 1
A handleChangeRaLocationCommand() 18 18 1
A handleRemoveRaLocationCommand() 0 13 1

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 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\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand;
31
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ChangeRaLocationCommand;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand;
33
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveRaLocationCommand;
34
35
/**
36
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects) Value objects
37
 */
38
class InstitutionConfigurationCommandHandler extends CommandHandler
39
{
40
    /**
41
     * @var RepositoryInterface
42
     */
43
    private $repository;
44
45
    public function __construct(RepositoryInterface $repository)
46
    {
47
        $this->repository = $repository;
48
    }
49
50
    public function handleCreateInstitutionConfigurationCommand(CreateInstitutionConfigurationCommand $command)
51
    {
52
        $institution                = new Institution($command->institution);
53
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
54
        $institutionConfiguration   = InstitutionConfiguration::create($institutionConfigurationId, $institution);
55
56
        $this->repository->save($institutionConfiguration);
57
    }
58
59 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...
60
    {
61
        $institution                = new Institution($command->institution);
62
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
63
64
        $institutionConfiguration = $this->repository->load(
65
            $institutionConfigurationId->getInstitutionConfigurationId()
66
        );
67
68
        $institutionConfiguration->addRaLocation(
69
            new RaLocationId($command->raLocationId),
70
            new RaLocationName($command->raLocationName),
71
            new Location($command->location),
72
            new ContactInformation($command->contactInformation)
73
        );
74
75
        $this->repository->save($institutionConfiguration);
76
    }
77
78 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...
79
    {
80
        $institution                = new Institution($command->institution);
81
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
82
83
        $institutionConfiguration = $this->repository->load(
84
            $institutionConfigurationId->getInstitutionConfigurationId()
85
        );
86
87
        $institutionConfiguration->changeRaLocation(
88
            new RaLocationId($command->raLocationId),
89
            new RaLocationName($command->raLocationName),
90
            new Location($command->location),
91
            new ContactInformation($command->contactInformation)
92
        );
93
94
        $this->repository->save($institutionConfiguration);
95
    }
96
97
    public function handleRemoveRaLocationCommand(RemoveRaLocationCommand $command)
98
    {
99
        $institution                = new Institution($command->institution);
100
        $institutionConfigurationId = InstitutionConfigurationId::from($institution);
101
102
        $institutionConfiguration = $this->repository->load(
103
            $institutionConfigurationId->getInstitutionConfigurationId()
104
        );
105
106
        $institutionConfiguration->removeRaLocation(new RaLocationId($command->raLocationId));
107
108
        $this->repository->save($institutionConfiguration);
109
    }
110
}
111