Completed
Push — feature/ra-locations-model ( d07346 )
by A.
05:06
created

applyRaLocationAddedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 0
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\Stepup\Configuration;
20
21
use Broadway\EventSourcing\EventSourcedAggregateRoot;
22
use Surfnet\Stepup\Configuration\Api\InstitutionConfiguration as InstitutionConfigurationInterface;
23
use Surfnet\Stepup\Configuration\Value\ContactInformation;
24
use Surfnet\Stepup\Configuration\Value\Institution;
25
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId;
26
use Surfnet\Stepup\Configuration\Value\Location;
27
use Surfnet\Stepup\Configuration\Value\RaLocationId;
28
use Surfnet\Stepup\Configuration\Value\RaLocationList;
29
use Surfnet\Stepup\Configuration\Value\RaLocationName;
30
use Surfnet\Stepup\Exception\DomainException;
31
32
class InstitutionConfiguration extends EventSourcedAggregateRoot implements InstitutionConfigurationInterface
33
{
34
    /**
35
     * @var InstitutionConfigurationId
36
     */
37
    private $institutionConfigurationId;
38
39
    /**
40
     * @var RaLocationList
41
     */
42
    private $raLocations;
43
44
    /**
45
     * @param InstitutionConfigurationId $institutionConfigurationId
46
     * @param Institution $institution
47
     * @return InstitutionConfiguration
0 ignored issues
show
Documentation introduced by
Should the return type not be InstitutionConfiguration|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
48
     */
49
    public static function create(InstitutionConfigurationId $institutionConfigurationId, Institution $institution)
50
    {
51
        // new self
52
        // apply institution configuration created event
53
    }
54
55
    final private function __construct()
0 ignored issues
show
introduced by
Instead of declaring the constructor as final, maybe you should declare the entire class as final.
Loading history...
56
    {
57
    }
58
59
    public function addRaLocation(
60
        RaLocationId $raLocationId,
61
        RaLocationName $raLocationName,
62
        Location $location,
63
        ContactInformation $contactInformation
64
    ) {
65 View Code Duplication
        if ($this->raLocations->hasWith($raLocationId)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
66
            throw new DomainException(sprintf(
67
                'Cannot add RaLocation with RaLocationId "%s" to RaLocations of InstitutionConfiguration "%s":'
68
                . 'it is already present',
69
                $raLocationId,
70
                $this->getAggregateRootId()
71
            ));
72
        }
73
74
        // apply ra location added event
75
    }
76
77
    public function changeRaLocation(
78
        RaLocationId $raLocationId,
79
        RaLocationName $raLocationName,
80
        Location $location,
81
        ContactInformation $contactInformation
82
    ) {
83 View Code Duplication
        if (!$this->raLocations->hasWith($raLocationId)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
            throw new DomainException(sprintf(
85
                'Cannot change RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":'
86
                . 'it is not present',
87
                $raLocationId,
88
                $this->getAggregateRootId()
89
            ));
90
        }
91
92
        $raLocation = $this->raLocations->getBy($raLocationId);
93
94
        if (!$raLocation->getLocationName()->equals($raLocationName)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
95
            // apply renamed event
96
        }
97
        if (!$raLocation->getLocation()->equals($location)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
98
            // apply relocated event
99
        }
100
        if (!$raLocation->getContactInformation()->equals($contactInformation)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
101
            // apply contact information changed event
102
        }
103
    }
104
105
    public function removeRaLocation(RaLocationId $raLocationId)
106
    {
107 View Code Duplication
        if (!$this->raLocations->hasWith($raLocationId)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
108
            throw new DomainException(sprintf(
109
                'Cannot remove RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":'
110
                . 'it is not present',
111
                $raLocationId,
112
                $this->getAggregateRootId()
113
            ));
114
        }
115
116
        // apply ra location removed event
117
    }
118
119
    public function getAggregateRootId()
120
    {
121
        return $this->institutionConfigurationId;
122
    }
123
124
    public function applyInstitutionConfigurationCreatedEvent()
125
    {
126
        // Implement
127
    }
128
129
    public function applyRaLocationAddedEvent()
130
    {
131
        // Implement
132
    }
133
134
    public function applyRaLocationRenamedEvent()
135
    {
136
        // Implement
137
    }
138
139
    public function applyRaLocationRelocatedEvent()
140
    {
141
        // Implement
142
    }
143
144
    public function applyRaLocationContactInformationChangedEvent()
145
    {
146
        // Implement
147
    }
148
149
    public function applyRaLocationRemovedEvent()
150
    {
151
        // Implement
152
    }
153
}
154