Passed
Pull Request — main (#308)
by Paul
18:42 queued 09:10
created

AuthenticatedIdentity   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 63
rs 10
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getSalt() 0 4 1
A getPassword() 0 4 1
A getRoles() 0 4 1
A getUsername() 0 3 2
A getIdentity() 0 3 1
A eraseCredentials() 0 3 1
A getUserIdentifier() 0 4 1
A getOriginalIdentity() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2023 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\Security\Authentication;
22
23
use Symfony\Component\Security\Core\User\UserInterface;
24
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity;
25
26
readonly class AuthenticatedIdentity implements UserInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class AuthenticatedIdentity
Loading history...
27
{
28
    public function __construct(private Identity $originalIdentity)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
29
    {
30
    }
31
32
    public function getIdentity(): Identity
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getIdentity()
Loading history...
33
    {
34
        return $this->originalIdentity;
35
    }
36
37
    public function getUsername(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getUsername()
Loading history...
38
    {
39
        return $this->originalIdentity->id ?: '';
40
    }
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @inheritDoc
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
45
    public function getRoles(): array
46
    {
47
        // You can customize this method based on your application's logic.
48
        return ['ROLE_USER'];
49
    }
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @inheritDoc
53
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
54
    public function getPassword(): ?string
55
    {
56
        // You may not store the password in this DTO, return null.
57
        return null;
58
    }
59
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @inheritDoc
62
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
63
    public function getSalt(): ?string
64
    {
65
        // You may not store a salt in this DTO, return null.
66
        return null;
67
    }
68
69
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @inheritDoc
71
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
72
    public function eraseCredentials(): array
73
    {
74
        return [];
75
    }
76
77
    /**
78
     * Allow access to the original Identity instance if needed.
79
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
80
    public function getOriginalIdentity(): Identity
81
    {
82
        return $this->originalIdentity;
83
    }
84
85
    public function getUserIdentifier(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getUserIdentifier()
Loading history...
86
    {
87
        $parts = explode(':', $this->originalIdentity->nameId);
88
        return end($parts);
89
    }
90
}
91