Completed
Push — master ( 6e52f0...d9a404 )
by Alexandre
02:29
created

BearerToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 7 2
A __construct() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 02/01/2018
6
 * Time: 17:53
7
 */
8
9
namespace OAuth2OLD\Credential\TokenType;
10
11
12
/**
13
 * Class BearerToken
14
 * @package OAuth2\Credentials\Token
15
 *
16
 * @see https://tools.ietf.org/html/rfc6750
17
 *
18
 * Bearer Token
19
 *
20
 *     A security token with the property that any party in possession of
21
 * the token (a "bearer") can use the token in any way that any other
22
 * party in possession of it can.  Using a bearer token does not
23
 * require a bearer to prove possession of cryptographic key material
24
 * (proof-of-possession).
25
 */
26
class BearerToken
27
{
28
    const CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._";
29
    const LENGTH = 16;
30
    /**
31
     * @var string
32
     */
33
    private $token;
34
35
    public function __construct(string $token)
36
    {
37
        $this->token = $token;
38
    }
39
40
    static function generate($length = self::LENGTH)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
    {
42
        $token = '';
43
        for ($i = 0; $i < $length; ++$i) {
44
            $token .= self::CHARS[random_int(0, strlen(self::CHARS))];
45
        }
46
        return new self('Bearer '.base64_encode($token));
47
    }
48
}