JWTLoggedInUserProvider::getUser()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 10
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 10
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
}