Completed
Push — main ( a0d26b...ad8384 )
by
unknown
20s queued 17s
created

WhitelistProjector::applyIdentityForgottenEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2014 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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupMiddleware\GatewayBundle\Projector;
20
21
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
22
use Surfnet\Stepup\Projector\Projector;
23
use Surfnet\Stepup\Identity\Event\InstitutionsAddedToWhitelistEvent;
24
use Surfnet\Stepup\Identity\Event\InstitutionsRemovedFromWhitelistEvent;
25
use Surfnet\Stepup\Identity\Event\WhitelistCreatedEvent;
26
use Surfnet\Stepup\Identity\Event\WhitelistReplacedEvent;
27
use Surfnet\StepupMiddleware\GatewayBundle\Entity\WhitelistEntry;
28
use Surfnet\StepupMiddleware\GatewayBundle\Repository\WhitelistEntryRepository;
29
30
class WhitelistProjector extends Projector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class WhitelistProjector
Loading history...
31
{
32
    public function __construct(private readonly WhitelistEntryRepository $whitelistEntryRepository)
33
    {
34
    }
35
36
    protected function applyWhitelistCreatedEvent(WhitelistCreatedEvent $event): void
37
    {
38
        $whitelistEntries = [];
39
        foreach ($event->whitelistedInstitutions as $institution) {
40
            $whitelistEntries[] = WhitelistEntry::createFrom($institution);
41
        }
42
43
        $this->whitelistEntryRepository->saveEntries($whitelistEntries);
44
    }
45
46
    protected function applyWhitelistReplacedEvent(WhitelistReplacedEvent $event): void
47
    {
48
        $this->whitelistEntryRepository->removeAll();
49
50
        $whitelistEntries = [];
51
        foreach ($event->whitelistedInstitutions as $institution) {
52
            $whitelistEntries[] = WhitelistEntry::createFrom($institution);
53
        }
54
55
        $this->whitelistEntryRepository->saveEntries($whitelistEntries);
56
    }
57
58
    protected function applyInstitutionsAddedToWhitelistEvent(InstitutionsAddedToWhitelistEvent $event): void
59
    {
60
        $whitelistEntries = [];
61
        foreach ($event->addedInstitutions as $institution) {
62
            $whitelistEntries[] = WhitelistEntry::createFrom($institution);
63
        }
64
65
        $this->whitelistEntryRepository->saveEntries($whitelistEntries);
66
    }
67
68
    protected function applyInstitutionsRemovedFromWhitelistEvent(InstitutionsRemovedFromWhitelistEvent $event): void
69
    {
70
        $institutions = [];
71
        foreach ($event->removedInstitutions as $institution) {
72
            $institutions[] = $institution;
73
        }
74
75
        $whitelistEntries = $this->whitelistEntryRepository->findEntriesByInstitutions($institutions);
76
77
        $this->whitelistEntryRepository->remove($whitelistEntries);
78
    }
79
80
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
81
    {
82
        // do nothing, no sensitive data in this projection
83
    }
84
}
85