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

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 2022 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\IdentityForgottenEvent;
22
use Surfnet\Stepup\Projector\Projector;
23
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent;
24
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
25
use Surfnet\Stepup\Identity\Event\SecondFactorVettedWithoutTokenProofOfPossession;
26
use Surfnet\Stepup\Identity\Value\IdentityId;
27
use Surfnet\Stepup\Identity\Value\VettingType;
28
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\IdentitySelfAssertedTokenOptions;
29
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentitySelfAssertedTokenOptionsRepository;
30
31
class IdentitySelfAssertedTokenOptionsProjector extends Projector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class IdentitySelfAssertedTokenOptionsProjector
Loading history...
32
{
33
    public function __construct(
34
        private readonly IdentitySelfAssertedTokenOptionsRepository $repository,
35
    ) {
36
    }
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $event should have a doc-comment as per coding-style.
Loading history...
39
     * Identity is created, we also create a set of
40
     * IdentitySelfAssertedTokenOptions.
41
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
42
    public function applyIdentityCreatedEvent(IdentityCreatedEvent $event): void
43
    {
44
        $identitySelfAssertedTokenOptions = IdentitySelfAssertedTokenOptions::create(
45
            $event->identityId,
46
            false,
47
            false,
48
        );
49
        $this->repository->save($identitySelfAssertedTokenOptions);
50
    }
51
52
    public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event): void
53
    {
54
        $this->determinePossessionOfToken($event->vettingType, $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...minePossessionOfToken() 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

54
        $this->determinePossessionOfToken(/** @scrutinizer ignore-type */ $event->vettingType, $event->identityId);
Loading history...
55
    }
56
57
    public function applySecondFactorVettedWithoutTokenProofOfPossession(
58
        SecondFactorVettedWithoutTokenProofOfPossession $event,
59
    ): void {
60
        $this->determinePossessionOfToken($event->vettingType, $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...minePossessionOfToken() 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

60
        $this->determinePossessionOfToken(/** @scrutinizer ignore-type */ $event->vettingType, $event->identityId);
Loading history...
61
    }
62
63
    private function determinePossessionOfToken(VettingType $vettingType, IdentityId $identityId): void
0 ignored issues
show
Coding Style introduced by
Private method name "IdentitySelfAssertedTokenOptionsProjector::determinePossessionOfToken" must be prefixed with an underscore
Loading history...
64
    {
65
        $isSelfAssertedToken = $vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION;
66
        $identitySelfAssertedTokenOptions = $this->repository->find($identityId);
67
        // Scenario 1: A new token is registered, we have no sat options yet,
68
        // create them. These are identities from the pre SAT era.
69
        if (!$identitySelfAssertedTokenOptions instanceof IdentitySelfAssertedTokenOptions) {
70
            $identitySelfAssertedTokenOptions = IdentitySelfAssertedTokenOptions::create(
71
                $identityId,
72
                true,
73
                $isSelfAssertedToken,
74
            );
75
            $this->repository->save($identitySelfAssertedTokenOptions);
76
            return;
77
        }
78
        // Scenario 2: handle vetting of an Identity with IdentitySelfAssertedTokenOptions
79
        if ($vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION) {
80
            $identitySelfAssertedTokenOptions->possessedSelfAssertedToken = true;
81
        }
82
        $identitySelfAssertedTokenOptions->possessedToken = true;
83
        $this->repository->save($identitySelfAssertedTokenOptions);
84
    }
85
86
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
87
    {
88
        // do nothing, no sensitive data in this projection
89
    }
90
}
91