JWTLoggedInUserProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
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
}