KeyGenerator::generate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\OAuth2;
4
5
6
/**
7
 * KeyGenerator
8
 * @package kalanis\OAuth2
9
 */
10 1
class KeyGenerator implements IKeyGenerator
11
{
12
    /** Key generator algorithm */
13
    public const ALGORITHM = 'sha256';
14
15
    /**
16
     * Generate random token
17
     * @param int $length
18
     */
19
    public function generate(int $length = 40): string
20
    {
21
        $bytes = openssl_random_pseudo_bytes($length);
22
        return hash(self::ALGORITHM, $bytes);
23
    }
24
}
25