SecurityClaims   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 5 1
A roleToString() 0 5 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Jwt\Claims;
6
7
use Damax\Bundle\ApiAuthBundle\Jwt\Claims;
8
use Symfony\Component\Security\Core\Role\Role;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
11
final class SecurityClaims implements Claims
12
{
13
    public function resolve(UserInterface $user): array
14
    {
15
        return [
16
            self::SUBJECT => $user->getUsername(),
17
            self::ROLES => array_map([$this, 'roleToString'], $user->getRoles()),
18
        ];
19
    }
20
21
    private function roleToString($role): string
22
    {
23
        $str = strtolower(strval($role instanceof Role ? $role->getRole() : $role));
24
25
        return 0 === strpos($str, 'role_') ? substr($str, 5) : $str;
26
    }
27
}
28