Completed
Push — main ( a0d26b...ad8384 )
by
unknown
20s queued 17s
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\Projector\Projector;
22
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent;
23
use Surfnet\Stepup\Identity\Event\IdentityEmailChangedEvent;
24
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
25
use Surfnet\Stepup\Identity\Event\IdentityRenamedEvent;
26
use Surfnet\Stepup\Identity\Event\LocalePreferenceExpressedEvent;
27
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
28
use Surfnet\Stepup\Identity\Event\SecondFactorVettedWithoutTokenProofOfPossession;
29
use Surfnet\Stepup\Identity\Value\VettingType;
30
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
31
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository;
32
33
class IdentityProjector extends Projector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class IdentityProjector
Loading history...
34
{
35
    public function __construct(
36
        private readonly IdentityRepository $identityRepository,
37
    ) {
38
    }
39
40
    public function applyIdentityCreatedEvent(IdentityCreatedEvent $event): void
41
    {
42
        $this->identityRepository->save(
43
            Identity::create(
44
                (string)$event->identityId,
45
                $event->identityInstitution,
46
                $event->nameId,
47
                $event->email,
48
                $event->commonName,
49
                $event->preferredLocale,
50
            ),
51
        );
52
    }
53
54
    public function applyIdentityRenamedEvent(IdentityRenamedEvent $event): void
55
    {
56
        $identity = $this->identityRepository->find((string)$event->identityId);
57
        $identity->commonName = $event->commonName;
58
59
        $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

59
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
60
    }
61
62
    public function applyIdentityEmailChangedEvent(IdentityEmailChangedEvent $event): void
63
    {
64
        $identity = $this->identityRepository->find((string)$event->identityId);
65
        $identity->email = $event->email;
66
67
        $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

67
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
68
    }
69
70
    public function applyLocalePreferenceExpressedEvent(LocalePreferenceExpressedEvent $event): void
71
    {
72
        $identity = $this->identityRepository->find((string)$event->identityId);
73
        $identity->preferredLocale = $event->preferredLocale;
74
75
        $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

75
        $this->identityRepository->save(/** @scrutinizer ignore-type */ $identity);
Loading history...
76
    }
77
78
    public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event): void
79
    {
80
        $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

80
        $this->determinePossessionOfSelfAssertedToken(/** @scrutinizer ignore-type */ $event->vettingType, (string)$event->identityId);
Loading history...
81
    }
82
83
    public function applySecondFactorVettedWithoutTokenProofOfPossession(
84
        SecondFactorVettedWithoutTokenProofOfPossession $event,
85
    ): void {
86
        $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

86
        $this->determinePossessionOfSelfAssertedToken(/** @scrutinizer ignore-type */ $event->vettingType, (string)$event->identityId);
Loading history...
87
    }
88
89
    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...
90
    {
91
        if ($vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION) {
92
            $identity = $this->identityRepository->find($identityId);
93
            if ($identity instanceof Identity) {
94
                $identity->possessedSelfAssertedToken = true;
95
                $this->identityRepository->save($identity);
96
            }
97
        }
98
    }
99
100
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
101
    {
102
        $this->identityRepository->updateStatusByIdentityIdToForgotten($event->identityId);
103
    }
104
}
105