TimestampClaims::resolve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
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 Lcobucci\Clock\Clock;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
11
final class TimestampClaims implements Claims
12
{
13
    private $clock;
14
    private $ttl;
15
16
    public function __construct(Clock $clock, int $ttl)
17
    {
18
        $this->clock = $clock;
19
        $this->ttl = $ttl;
20
    }
21
22
    public function resolve(UserInterface $user): array
23
    {
24
        $now = $this->clock->now();
25
26
        return [
27
            self::ISSUED_AT => $now,
28
            self::NOT_BEFORE => $now,
29
            self::EXPIRATION_TIME => $now->modify(sprintf('+%d seconds', $this->ttl)),
30
        ];
31
    }
32
}
33