RecoveryToken   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 56
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A complyWithRevocation() 0 9 1
A create() 0 11 1
A getTokenId() 0 3 1
A getType() 0 3 1
A revoke() 0 8 1
A __construct() 0 2 1
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
 */
18
19
namespace Surfnet\Stepup\Identity\Entity;
20
21
use Broadway\EventSourcing\EventSourcedAggregateRoot;
22
use Broadway\EventSourcing\SimpleEventSourcedEntity;
23
use Surfnet\Stepup\Identity\Api\Identity;
24
use Surfnet\Stepup\Identity\Event\CompliedWithRecoveryCodeRevocationEvent;
25
use Surfnet\Stepup\Identity\Event\RecoveryTokenRevokedEvent;
26
use Surfnet\Stepup\Identity\Value\IdentityId;
27
use Surfnet\Stepup\Identity\Value\RecoveryTokenId;
28
use Surfnet\Stepup\Identity\Value\RecoveryTokenType;
29
30
final class RecoveryToken extends SimpleEventSourcedEntity
31
{
32
    private ?RecoveryTokenId $tokenId = null;
33
34
    private ?RecoveryTokenType $type = null;
35
36
    private ?Identity $identity = null;
37
38
    public static function create(
39
        RecoveryTokenId $id,
40
        RecoveryTokenType $type,
41
        Identity&EventSourcedAggregateRoot $identity,
42
    ): self {
43
        $token = new self;
0 ignored issues
show
Coding Style introduced by
Parentheses must be used when instantiating a new class
Loading history...
44
        $token->tokenId = $id;
45
        $token->type = $type;
46
        $token->identity = $identity;
47
        $token->registerAggregateRoot($identity);
48
        return $token;
49
    }
50
51
    final public function __construct()
52
    {
53
    }
54
55
    public function getTokenId(): RecoveryTokenId
56
    {
57
        return $this->tokenId;
58
    }
59
60
    public function getType(): RecoveryTokenType
61
    {
62
        return $this->type;
63
    }
64
65
    public function revoke(): void
66
    {
67
        $this->apply(
68
            new RecoveryTokenRevokedEvent(
69
                $this->identity->getId(),
0 ignored issues
show
Bug introduced by
The method getId() does not exist on null. ( Ignorable by Annotation )

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

69
                $this->identity->/** @scrutinizer ignore-call */ 
70
                                 getId(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
                $this->identity->getInstitution(),
71
                $this->tokenId,
0 ignored issues
show
Bug introduced by
It seems like $this->tokenId can also be of type null; however, parameter $recoveryTokenId of Surfnet\Stepup\Identity\...kedEvent::__construct() does only seem to accept Surfnet\Stepup\Identity\Value\RecoveryTokenId, 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

71
                /** @scrutinizer ignore-type */ $this->tokenId,
Loading history...
72
                $this->type,
0 ignored issues
show
Bug introduced by
It seems like $this->type can also be of type null; however, parameter $recoveryTokenType of Surfnet\Stepup\Identity\...kedEvent::__construct() does only seem to accept Surfnet\Stepup\Identity\Value\RecoveryTokenType, 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

72
                /** @scrutinizer ignore-type */ $this->type,
Loading history...
73
            ),
74
        );
75
    }
76
77
    public function complyWithRevocation(IdentityId $authorityId): void
78
    {
79
        $this->apply(
80
            new CompliedWithRecoveryCodeRevocationEvent(
81
                $this->identity->getId(),
82
                $this->identity->getInstitution(),
83
                $this->tokenId,
0 ignored issues
show
Bug introduced by
It seems like $this->tokenId can also be of type null; however, parameter $recoveryTokenId of Surfnet\Stepup\Identity\...ionEvent::__construct() does only seem to accept Surfnet\Stepup\Identity\Value\RecoveryTokenId, 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

83
                /** @scrutinizer ignore-type */ $this->tokenId,
Loading history...
84
                $this->type,
0 ignored issues
show
Bug introduced by
It seems like $this->type can also be of type null; however, parameter $recoveryTokenType of Surfnet\Stepup\Identity\...ionEvent::__construct() does only seem to accept Surfnet\Stepup\Identity\Value\RecoveryTokenType, 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

84
                /** @scrutinizer ignore-type */ $this->type,
Loading history...
85
                $authorityId,
86
            ),
87
        );
88
    }
89
}
90