JWTLoggedInUserProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
ccs 7
cts 9
cp 0.7778
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUser() 0 10 3
1
<?php
2
3
namespace App\Infrastructure\Security;
4
5
use Symfony\Component\Security\Core\Security;
6
7
/**
8
 * This Provider uses User information stored in the Authorization JWT Token
9
 */
10
class JWTLoggedInUserProvider implements LoggedInUserProviderInterface
11
{
12
13 7
    public function __construct(
14
        private Security $security
15
    )
16
    {
17 7
    }
18
19 7
   public function getUser(): LoggedInUser
20
    {
21 7
        $user = $this->security->getUser();
22 7
        if ($user == null) {
23
            throw new \RuntimeException("You are not logged in!");
24
        }
25 7
        if ($user instanceof LoggedInUser) {
26 7
            return $user;
27
        }
28
        throw new \RuntimeException("Unsupported User Class: " . $user::class);
29
    }
30
}