JwtGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 10 1
1
<?php
2
3
/**
4
 * This file is part of the BEAR.JwtAuthModule package.
5
 *
6
 * @license http://opensource.org/licenses/MIT MIT
7
 */
8
namespace BEAR\JwtAuth\Generator;
9
10
use BEAR\JwtAuth\Annotation\Ttl;
11
use BEAR\JwtAuth\Encoder\JwtEncoderInject;
12
13
class JwtGenerator implements JwtGeneratorInterface
14
{
15
    use JwtEncoderInject;
16
17
    /**
18
     * @var int
19
     */
20
    private $ttl;
21
22
    /**
23
     * @Ttl("ttl")
24
     */
25 4
    public function __construct(string $ttl)
26
    {
27 4
        $this->ttl = $ttl;
0 ignored issues
show
Documentation Bug introduced by
The property $ttl was declared of type integer, but $ttl is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
28 4
    }
29
30 1
    public function create(array $payload) : string
31
    {
32 1
        $now = time();
33 1
        $payload['exp'] = $now + $this->ttl;
34 1
        $payload['iat'] = $now;
35
36 1
        $token = $this->jwtEncoder->encode($payload);
37
38 1
        return $token;
39
    }
40
}
41