SecondFactorRevocationEmailProcessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handleCompliedWithVettedSecondFactorRevocationEvent() 0 15 2
A handleVettedSecondFactorRevokedEvent() 0 14 2
A __construct() 0 4 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\Processor;
20
21
use Broadway\Processor\Processor;
22
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
23
use Surfnet\Stepup\Identity\Event\SecondFactorRevokedEvent;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\IdentityService;
26
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\SecondFactorRevocationMailService;
27
28
final class SecondFactorRevocationEmailProcessor extends Processor
29
{
30
    public function __construct(
31
        private readonly SecondFactorRevocationMailService $mailService,
32
        private readonly IdentityService $identityService,
33
    ) {
34
    }
35
36
    public function handleCompliedWithVettedSecondFactorRevocationEvent(
37
        CompliedWithVettedSecondFactorRevocationEvent $event,
38
    ): void {
39
        $identity = $this->identityService->find($event->identityId->getIdentityId());
40
41
        if (!$identity instanceof Identity) {
42
            return;
43
        }
44
45
        $this->mailService->sendVettedSecondFactorRevokedByRaEmail(
46
            $identity->preferredLocale,
47
            $identity->commonName,
48
            $identity->email,
49
            $event->secondFactorType,
50
            $event->secondFactorIdentifier,
51
        );
52
    }
53
54
    public function handleVettedSecondFactorRevokedEvent(SecondFactorRevokedEvent $event): void
55
    {
56
        $identity = $this->identityService->find($event->identityId->getIdentityId());
57
58
        if (!$identity instanceof Identity) {
59
            return;
60
        }
61
62
        $this->mailService->sendVettedSecondFactorRevokedByRegistrantEmail(
63
            $identity->preferredLocale,
64
            $identity->commonName,
65
            $identity->email,
66
            $event->secondFactorType,
67
            $event->secondFactorIdentifier,
68
        );
69
    }
70
}
71