Passed
Push — bugfix/fix-deprovision-anonymi... ( aa4a6e...ce6ef9 )
by
unknown
04:58
created

RaLocationProjector::fetchRaLocationById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\Projector;
20
21
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
22
use Surfnet\Stepup\Projector\Projector;
23
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
24
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent;
25
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent;
26
use Surfnet\Stepup\Configuration\Event\RaLocationRelocatedEvent;
27
use Surfnet\Stepup\Configuration\Event\RaLocationRemovedEvent;
28
use Surfnet\Stepup\Configuration\Event\RaLocationRenamedEvent;
29
use Surfnet\Stepup\Configuration\Value\RaLocationId;
30
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\RaLocation;
31
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\RaLocationRepository;
32
use Surfnet\StepupMiddleware\ApiBundle\Exception\RuntimeException;
33
34
class RaLocationProjector extends Projector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class RaLocationProjector
Loading history...
35
{
36
    public function __construct(private readonly RaLocationRepository $repository)
37
    {
38
    }
39
40
    public function applyRaLocationAddedEvent(RaLocationAddedEvent $event): void
41
    {
42
        $raLocation = RaLocation::create(
43
            $event->raLocationId->getRaLocationId(),
44
            $event->institution,
45
            $event->raLocationName,
46
            $event->location,
47
            $event->contactInformation,
48
        );
49
50
        $this->repository->save($raLocation);
51
    }
52
53
    public function applyRaLocationRenamedEvent(RaLocationRenamedEvent $event): void
54
    {
55
        $raLocation = $this->fetchRaLocationById($event->raLocationId);
56
57
        $raLocation->name = $event->raLocationName;
58
59
        $this->repository->save($raLocation);
60
    }
61
62
    public function applyRaLocationRelocatedEvent(RaLocationRelocatedEvent $event): void
63
    {
64
        $raLocation = $this->fetchRaLocationById($event->raLocationId);
65
66
        $raLocation->location = $event->location;
67
68
        $this->repository->save($raLocation);
69
    }
70
71
    public function applyRaLocationContactInformationChangedEvent(RaLocationContactInformationChangedEvent $event): void
72
    {
73
        $raLocation = $this->fetchRaLocationById($event->raLocationId);
74
75
        $raLocation->contactInformation = $event->contactInformation;
76
77
        $this->repository->save($raLocation);
78
    }
79
80
    public function applyRaLocationRemovedEvent(RaLocationRemovedEvent $event): void
81
    {
82
        $raLocation = $this->fetchRaLocationById($event->raLocationId);
83
84
        $this->repository->remove($raLocation);
85
    }
86
87
    public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event): void
88
    {
89
        $this->repository->removeRaLocationsFor($event->institution);
90
    }
91
92
    private function fetchRaLocationById(RaLocationId $raLocationId): RaLocation
0 ignored issues
show
Coding Style introduced by
Private method name "RaLocationProjector::fetchRaLocationById" must be prefixed with an underscore
Loading history...
93
    {
94
        $raLocation = $this->repository->findByRaLocationId($raLocationId);
95
96
        if (is_null($raLocation)) {
97
            throw new RuntimeException(
98
                'Tried to update an RA Locations contact information, but location could not be found',
99
            );
100
        }
101
102
        return $raLocation;
103
    }
104
105
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
106
        // do nothing, no sensitive data in this projection
107
    }
108
}
109