RecoveryTokenEmailProcessor   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handlePhoneRecoveryTokenPossessionProvenEvent() 0 11 2
A handleCompliedWithRecoveryCodeRevocationEvent() 0 16 2
A __construct() 0 4 1
A handleRecoveryTokenRevokedEvent() 0 15 2
A handleSafeStoreSecretRecoveryTokenPossessionPromisedEvent() 0 12 2
1
<?php
2
3
/**
4
 * Copyright 2022 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\CommandHandlingBundle\Processor;
20
21
use Broadway\Processor\Processor;
22
use Surfnet\Stepup\Identity\Event\CompliedWithRecoveryCodeRevocationEvent;
23
use Surfnet\Stepup\Identity\Event\PhoneRecoveryTokenPossessionProvenEvent;
24
use Surfnet\Stepup\Identity\Event\RecoveryTokenRevokedEvent;
25
use Surfnet\Stepup\Identity\Event\SafeStoreSecretRecoveryTokenPossessionPromisedEvent;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
27
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\IdentityService;
28
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\RecoveryTokenMailService;
29
30
final class RecoveryTokenEmailProcessor extends Processor
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class RecoveryTokenEmailProcessor
Loading history...
31
{
32
    public function __construct(
33
        private readonly RecoveryTokenMailService $mailService,
34
        private readonly IdentityService $identityService,
35
    ) {
36
    }
37
38
    public function handleCompliedWithRecoveryCodeRevocationEvent(
39
        CompliedWithRecoveryCodeRevocationEvent $event,
40
    ): void {
41
        $identity = $this->identityService->find($event->identityId->getIdentityId());
42
43
        if (!$identity instanceof Identity) {
44
            return;
45
        }
46
47
        $this->mailService->sendRevoked(
48
            $identity->preferredLocale,
49
            $identity->commonName,
50
            $identity->email,
51
            $event->recoveryTokenType,
52
            $event->recoveryTokenId,
53
            true,
54
        );
55
    }
56
57
    public function handleRecoveryTokenRevokedEvent(RecoveryTokenRevokedEvent $event): void
58
    {
59
        $identity = $this->identityService->find($event->identityId->getIdentityId());
60
61
        if (!$identity instanceof Identity) {
62
            return;
63
        }
64
65
        $this->mailService->sendRevoked(
66
            $identity->preferredLocale,
67
            $identity->commonName,
68
            $identity->email,
69
            $event->recoveryTokenType,
70
            $event->recoveryTokenId,
71
            false,
72
        );
73
    }
74
75
    public function handlePhoneRecoveryTokenPossessionProvenEvent(PhoneRecoveryTokenPossessionProvenEvent $event): void
76
    {
77
        $identity = $this->identityService->find($event->identityId->getIdentityId());
78
79
        if (!$identity instanceof Identity) {
80
            return;
81
        }
82
        $this->mailService->sendCreated(
83
            $identity->preferredLocale,
84
            $event->commonName,
85
            $event->email,
86
        );
87
    }
88
89
    public function handleSafeStoreSecretRecoveryTokenPossessionPromisedEvent(
90
        SafeStoreSecretRecoveryTokenPossessionPromisedEvent $event,
91
    ): void {
92
        $identity = $this->identityService->find($event->identityId->getIdentityId());
93
94
        if (!$identity instanceof Identity) {
95
            return;
96
        }
97
        $this->mailService->sendCreated(
98
            $identity->preferredLocale,
99
            $event->commonName,
100
            $event->email,
101
        );
102
    }
103
}
104