GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( d1fd57...d85002 )
by Dmitri
01:47
created

Builder::fromUser()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Jwt\Lcobucci;
6
7
use Damax\Bundle\ApiAuthBundle\Jwt\Claims;
8
use Damax\Bundle\ApiAuthBundle\Jwt\TokenBuilder;
9
use Lcobucci\JWT\Configuration as JwtConfiguration;
10
use Symfony\Component\Security\Core\User\UserInterface;
11
12
final class Builder implements TokenBuilder
13
{
14
    private const CLAIM_TO_METHOD = [
15
        Claims::SUBJECT => 'relatedTo',
16
        Claims::ISSUER => 'issuedBy',
17
        Claims::AUDIENCE => 'permittedFor',
18
        Claims::ISSUED_AT => 'issuedAt',
19
        Claims::NOT_BEFORE => 'canOnlyBeUsedAfter',
20
        Claims::EXPIRATION_TIME => 'expiresAt',
21
        Claims::ID => 'identifiedBy',
22
    ];
23
24
    private $config;
25
    private $claims;
26
27
    public function __construct(JwtConfiguration $config, Claims $claims)
28
    {
29
        $this->config = $config;
30
        $this->claims = $claims;
31
    }
32
33
    public function fromUser(UserInterface $user): string
34
    {
35
        $builder = $this->config->createBuilder();
36
37
        foreach ($this->claims->resolve($user) as $name => $value) {
38
            $method = self::CLAIM_TO_METHOD[$name] ?? null;
39
40
            if ($method) {
41
                $builder->{$method}($value);
42
            } else {
43
                $builder->withClaim($name, $value);
44
            }
45
        }
46
47
        return (string) $builder->getToken($this->config->getSigner(), $this->config->getSigningKey());
48
    }
49
}
50