Passed
Push — main ( ad8384...b61e7a )
by
unknown
22:06 queued 16:15
created

IdentityProjector::applyIdentityForgottenEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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\ApiBundle\Identity\Projector;
20
21
use Surfnet\Stepup\Identity\Event\IdentityRestoredEvent;
22
use Surfnet\Stepup\Projector\Projector;
23
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent;
24
use Surfnet\Stepup\Identity\Event\IdentityEmailChangedEvent;
25
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
26
use Surfnet\Stepup\Identity\Event\IdentityRenamedEvent;
27
use Surfnet\Stepup\Identity\Event\LocalePreferenceExpressedEvent;
28
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
29
use Surfnet\Stepup\Identity\Event\SecondFactorVettedWithoutTokenProofOfPossession;
30
use Surfnet\Stepup\Identity\Value\VettingType;
31
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
32
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository;
33
34
class IdentityProjector extends Projector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class IdentityProjector
Loading history...
35
{
36
    public function __construct(
37
        private readonly IdentityRepository $identityRepository,
38
    ) {
39
    }
40
41
    public function applyIdentityCreatedEvent(IdentityCreatedEvent $event): void
42
    {
43
        $this->identityRepository->save(
44
            Identity::create(
45
                (string)$event->identityId,
46
                $event->identityInstitution,
47
                $event->nameId,
48
                $event->email,
49
                $event->commonName,
50
                $event->preferredLocale,
51
            ),
52
        );
53
    }
54
55
    public function applyIdentityRenamedEvent(IdentityRenamedEvent $event): void
56
    {
57
        $identity = $this->identityRepository->find((string)$event->identityId);
58
        $identity->commonName = $event->commonName;
59
60
        $this->identityRepository->save($identity);
0 ignored issues
show
Bug introduced by
It seems like $identity can also be of type null; however, parameter $identity of Surfnet\StepupMiddleware...ntityRepository::save() does only seem to accept Surfnet\StepupMiddleware...dentity\Entity\Identity, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
61
    }
62
63
    public function applyIdentityEmailChangedEvent(IdentityEmailChangedEvent $event): void
64
    {
65
        $identity = $this->identityRepository->find((string)$event->identityId);
66
        $identity->email = $event->email;
67
68
        $this->identityRepository->save($identity);
0 ignored issues
show
Bug introduced by
It seems like $identity can also be of type null; however, parameter $identity of Surfnet\StepupMiddleware...ntityRepository::save() does only seem to accept Surfnet\StepupMiddleware...dentity\Entity\Identity, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
69
    }
70
71
    public function applyLocalePreferenceExpressedEvent(LocalePreferenceExpressedEvent $event): void
72
    {
73
        $identity = $this->identityRepository->find((string)$event->identityId);
74
        $identity->preferredLocale = $event->preferredLocale;
75
76
        $this->identityRepository->save($identity);
0 ignored issues
show
Bug introduced by
It seems like $identity can also be of type null; however, parameter $identity of Surfnet\StepupMiddleware...ntityRepository::save() does only seem to accept Surfnet\StepupMiddleware...dentity\Entity\Identity, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
77
    }
78
79
    public function applyIdentityRestoredEvent(IdentityRestoredEvent $event): void
80
    {
81
        $identity = $this->identityRepository->find((string)$event->identityId);
82
        $identity->email = $event->email;
83
        $identity->commonName = $event->commonName;
84
85
        $this->identityRepository->save($identity);
0 ignored issues
show
Bug introduced by
It seems like $identity can also be of type null; however, parameter $identity of Surfnet\StepupMiddleware...ntityRepository::save() does only seem to accept Surfnet\StepupMiddleware...dentity\Entity\Identity, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
86
    }
87
88
89
    public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event): void
90
    {
91
        $this->determinePossessionOfSelfAssertedToken($event->vettingType, (string)$event->identityId);
0 ignored issues
show
Bug introduced by
It seems like $event->vettingType can also be of type null; however, parameter $vettingType of Surfnet\StepupMiddleware...onOfSelfAssertedToken() does only seem to accept Surfnet\Stepup\Identity\Value\VettingType, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
        $this->determinePossessionOfSelfAssertedToken(/** @scrutinizer ignore-type */ $event->vettingType, (string)$event->identityId);
Loading history...
92
    }
93
94
    public function applySecondFactorVettedWithoutTokenProofOfPossession(
95
        SecondFactorVettedWithoutTokenProofOfPossession $event,
96
    ): void {
97
        $this->determinePossessionOfSelfAssertedToken($event->vettingType, (string)$event->identityId);
0 ignored issues
show
Bug introduced by
It seems like $event->vettingType can also be of type null; however, parameter $vettingType of Surfnet\StepupMiddleware...onOfSelfAssertedToken() does only seem to accept Surfnet\Stepup\Identity\Value\VettingType, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
        $this->determinePossessionOfSelfAssertedToken(/** @scrutinizer ignore-type */ $event->vettingType, (string)$event->identityId);
Loading history...
98
    }
99
100
    private function determinePossessionOfSelfAssertedToken(VettingType $vettingType, string $identityId): void
0 ignored issues
show
Coding Style introduced by
Private method name "IdentityProjector::determinePossessionOfSelfAssertedToken" must be prefixed with an underscore
Loading history...
101
    {
102
        if ($vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION) {
103
            $identity = $this->identityRepository->find($identityId);
104
            if ($identity instanceof Identity) {
105
                $identity->possessedSelfAssertedToken = true;
106
                $this->identityRepository->save($identity);
107
            }
108
        }
109
    }
110
111
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
112
    {
113
        $this->identityRepository->updateStatusByIdentityIdToForgotten($event->identityId);
114
    }
115
}
116